Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Miraaj

macrumors newbie
Original poster
Oct 2, 2014
3
0
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:

Code:
    - (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:

Code:
   - (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.
 
What have you tried? Be specific.

Have you tried the sample code related to NSXPCListener?
See the "Related sample code" links here:
https://developer.apple.com/library...ference/translated_content/NSXPCListener.html

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?
 
@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:

'Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.'

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:

10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access.

10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013 { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." } (handleMessage()/appleEventsD.cp #2072) client-reqs-q

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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.