XPCService not getting launched from app

Discussion in 'Mac Programming' started by Miraaj, Oct 10, 2014.

  1. Miraaj macrumors newbie

    Oct 2, 2014
    I am trying a simple sample app on XPCServices, in which I am following below steps:

    Step 1: Created a sample project and added target - XPCServices with name - HelperProcess to it. When the target is created XCode automatically generates below files:

    1. HelperProcessProtocol.h
    2. HelperProcess.h
    3. HelperProcess.m
    4. main.m

    Step 2: In main.m added a log statement within implementation of ServiceDelegate:

        - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
            // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
            NSLog(@"Log which is never displayed :(");
            // Configure the connection.
            // First, set the interface that the exported object implements.
            newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)];
            // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
            HelperProcess *exportedObject = [HelperProcess new];
            newConnection.exportedObject = exportedObject;
            // Resuming the connection allows the system to deliver more incoming messages.
            [newConnection resume];
            // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
            return YES;
    Step 3: In AppDelegate added below code in applicationDidFinishLaunching:

       - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
            // Insert code here to initialize your application
            _connectionToService = [[NSXPCConnection alloc] initWithServiceName:@"HelperProcess"];
            _connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)];
            [_connectionToService resume];
    Problem is -

    When I launch the app, neither the log added in listener:shouldAcceptNewConnection: is displayed nor the helper process appears in Activity Monitor :(

    Here is the code: XPCShootOut

    Note: I am trying this on XCode 6.0

    Is there any additional setup which I need to do to make it working? Please suggest.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    What have you tried? Be specific.

    Have you tried the sample code related to NSXPCListener?
    See the "Related sample code" links here:

    The "Sandboxing with NSXPCConnection" sample seems apt, since it appears to use two separate sub-processes. If you compile that sample exactly as given, does it work?

    If so, then what differences are there from your app, especially in non-code areas like the Info.plist of your main app.

    If the sample doesn't work when compiled, then try it on an earlier version of Xcode. The sample requires min versions: Xcode 4.4 and OS 10.8.

    If you haven't tried Apple's sample code, have you tried any other sample code? What's the URL?

    Did you pattern your own code after an example? What's the URL?
  3. Miraaj thread starter macrumors newbie

    Oct 2, 2014
    @chown thanks for your reply.

    I referred this sample from apple: AppSandboxLoginItemXPCDemo

    When I tried to run it on XCode 6, it displayed error message - 'No signing identity found'. Since I don't have registered mac developer account, in build settings for - iDecide and iDecideHelper I changed 'Code Signing Identity' as 'Don't Code Sign'.

    I got a warning for each of the targets:

    This time when I compiled the build, it worked as expected.

    Now I tried to follow the steps specified in its ReadMe.txt file, specifically I performed these steps in my sample app:

    Step 1: Updated - Main App Target -> Capabilities Tab

    a. Turned on 'App Sandbox'
    b. Turned on 'App Groups'
    c. Added an app group - 'XYZ'

    Step 2: Updated - Helper Target -> Capabilities Tab

    a. Turned on 'App Sandbox'
    b. Enabled 'Outgoing Connections (Client)'
    c. Turned on 'App Groups'
    d. Added an app group - 'XYZ'

    Step 3: Updated - Helper Target -> General Tab -> Bundle Identifier, added 'XYZ' prefix to it.

    On running the app in console it displayed these messages:

    Neither app performed its intended function nor it displayed the log message added in 'listener:shouldAcceptNewConnection:' delegate.

    I am clueless. Kindly suggest if I am missing any thing? Is it possible to get XPC service sample app working without a registered mac developer account?

Share This Page