I'd like to add an additional listener to my XPC service in order to accept method from additional protocol.
@interface ServiceDelegate1 : NSObject <NSXPCListenerDelegate>
@end
@implementation ServiceDelegate1
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
...
@end
@interface ServiceDelegate1 : NSObject <NSXPCListenerDelegate>
@end
@implementation ServiceDelegate2
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
...
@end
and in main( ) function I use those delegators to create 2 listeners.
ServiceDelegate1 *delegate1 = [ServiceDelegate1 new];
ServiceDelegate2 *delegate2 = [ServiceDelegate2 new];
NSXPCListener *listener1 = [[NSXPCListener alloc] initWithMachServiceName:@"com.xpc.service1"];
listener1.delegate = delegate1;
[listener1 resume];
NSXPCListener *listener2 = [[NSXPCListener alloc] initWithMachServiceName:@"com.xpc.service2"];
listener2.delegate = delegate2;
[listener2 resume];
I also added the additinal service to the xpc service plist invocation file (under /Library/LaunchDaemons):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.xpc.service1</string>
<key>RunAtLoad</key>
<true/>
<key>EnablePressuredExit</key>
<false/>
<key>POSIXSpawnType</key>
<string>Adaptive</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/myApp.app/Contents/XPCServices/myservice.xpc/Contents/MacOS/myservice</string>
</array>
<key>MachServices</key>
<dict>
<key>com.xpc.service1</key>
<true/>
<key>com.xpcƒ.service2</key>
<true/>
</dict>
</dict>
</plist>
However, it seems like after i add the second listener, I suddenly stop getting the serviceName in method implmented by the 2 delegators.
Perhaps anybody can tell me if this is the right way to achieve my goal ?
thanks !