Start XPC service outside the main loop

Hi, I was wondering if there's any limitation for the context where I initialize my xpc service.

This is the code that initialize my xpc service :

  listener_ = [[NSXPCListener alloc] 
     initWithMachServiceName:@"com.bla.bla"]; 
  xpcService *delegate = [xpcService new];
  listener_.delegate = delegate;
  [listener_ resume];
  [[NSRunLoop mainRunLoop] run];

Doing it from the main method and everything works just fine. However, when calling it from different method(main)/thread(main thread)... It doesn't accept remote calls although it seems like the listener was properly initialized.

I even tried to wrap this code to run on the main thread using the following wrapper

dispatch_sync(dispatch_get_main_queue(), ^{
  listener_ = [[NSXPCListener alloc] 
     initWithMachServiceName:@"com.bla.bla"]; 
  xpcService *delegate = [xpcService new];
  listener_.delegate = delegate;
  [listener_ resume];
}

where the [[NSRunLoop mainRunLoop] run]; is called from the main method...

So my question is what are the requirements to make the XPC work.. is it mandatory to call it from the main method ?

Are you working on an XPC Service (.xpcservice)? Or on a launchd daemon (or agent) that vends an XPC service via its MachServices property?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Start XPC service outside the main loop
 
 
Q