3

I've got a target in my Xcode project that generate XPCService. Now I wish to implement more functions of different context, so I'd like to add them into different protocol.

I wish that the current xpc service support connections from both protocols.

the default code for single protocol support looks like this :

    // 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];

whereas the ServiceDelegate has the following method :

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

and I set the protocol for that connection decisively without option to choose myFirstProtocol

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

now I have mySecondProtocol as well and I want to choose protocol according to connection attribute that I send on the client side .. I'm looking for some sort of identifier that help me select the right interface.

thanks !

Zohar81
  • 4,554
  • 5
  • 29
  • 82

1 Answers1

0

I'm trying out setting interfaces dynamically.

So, something like: 1.let the service export a protocol that has a single method requestInterface(kind: String) 2. let the connecting process call requestInterface with a string specifying what kind of interface it wants 3. at that point change the exportedInterface

ibash
  • 1,477
  • 17
  • 31