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:
Step 3: In AppDelegate added below code in applicationDidFinishLaunching:
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.
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];
}
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.