2

I'm trying to communicate my xpc service from LaunchDaemon.

LaunchDaemon is command line executable and LaunchAgent is xpc service.

Initiating my connection from main service(LaunchDaemon) like this:

NSXPCConnection * _connectionToService;

 _connectionToService = [[NSXPCConnection alloc] initWithMachServiceName:@"com.XpcService" options:NSXPCConnectionPrivileged];


 _connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(XpcServiceProtocol)];

 _connectionToService.interruptionHandler = ^{ NSLog(@"Connection Terminated"); };

 _connectionToService.invalidationHandler = ^{ NSLog(@"Connection Invalidated"); };

 [_connectionToService resume];

 //here calling required functions

Xpc-service listening like this:

@interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
@end 

@implementation ServiceDelegate

-(BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection: (NSXPCConnection *)newConnection { 

newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(XpcServiceProtocol)]; 

XpcService *exportedObject = [XpcService new];

newConnection.exportedObject = exportedObject;

[newConnection resume]; 

return YES; 

} 

@end 

int main(int argc, const char *argv[]) { 

ServiceDelegate *delegate = [ServiceDelegate new];

NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:@"com.XpcService"]; 

listener.delegate = delegate;

[listener resume]; 

return 0; 

}

In my case i'm getting Connection Invalidated error, my xpc couldn't even be started.

LaunchAgent & LaunchDaemon loaded perfectly, code signing was also be done. help me to find out what might be caused the problem? Thanks in advance.

Vitaly S.
  • 2,389
  • 26
  • 40
programmer 05
  • 74
  • 1
  • 11
  • hi, perhaps did you find any solution to this problem, cause I'm facing with similar issue. thanks ! – Zohar81 Dec 31 '17 at 07:26
  • Hi, @Zohar81 I run out of time so I found a temporary solution for that. using local socket I connected the Launchdaemon application with Launchagent application. – programmer 05 Jan 02 '18 at 04:44

0 Answers0