// // main.m // LocalMessagePort // // Created by Mayur Pawashe on 6/14/16. // Copyright © 2016 Sparkle Project. All rights reserved. // #import #import "SULocalMessagePort.h" #import "SULocalMessagePortDelegate.h" @interface ServiceDelegate : NSObject @end @implementation ServiceDelegate - (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection { // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection. // Configure the connection. newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SULocalMessagePortProtocol)]; newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SULocalMessagePortDelegate)]; newConnection.exportedObject = [[SULocalMessagePort alloc] initWithDelegate:newConnection.remoteObjectProxy]; // Resuming the connection allows the system to deliver more incoming messages. [newConnection resume]; return YES; } @end int main(int argc, const char *argv[]) { // Create the delegate for the service. ServiceDelegate *delegate = [ServiceDelegate new]; // Set up the one NSXPCListener for this service. It will handle all incoming connections. NSXPCListener *listener = [NSXPCListener serviceListener]; listener.delegate = delegate; // Resuming the serviceListener starts this service. This method does not return. [listener resume]; return 0; }