5
votes

I'm trying to create an XPC service, but the service doesn't seem to being created. In my service's main method, the first thing I do is make some calls to syslog so that I can see if the service ever starts running. These log messages never appear in the log.

I've checked all the bundle identifiers, executable names, and the bundle hierarchy but still the services don't seem to be created. In the application, immediately after I create and send a message via a XPC service connection my event handler is called with an XPC_ERROR_CONNECTION_INVALID error. I'm using the C-based XPC APIs.

Is there anything else I can try and do to make sure that the XPC service at least gets created?

3
Hi, perhaps you can tell me how do I look at all the xpc services (is it done by launchctl or other command ? ) thanks ! - Zohar81

3 Answers

6
votes

It turned out that I needed to code sign the application target and the XPC service target. This can be done in the Xcode project build settings, and can be set to "Ad-hoc Code Sign" without needing a Mac developer certificate.

enter image description here

2
votes

Also check your service name. I found that the default example in the project template doesn't include the fully qualified name. In the client code, I had to change this:

NSXPCConnection *connection = [[NSXPCConnection alloc] initWithServiceName:@"MyNetworkClient"];

to this:

NSXPCConnection *connection = [[NSXPCConnection alloc] initWithServiceName:@"com.example.MyNetworkClient"];

Double check that the XPC Target's Bundle ID is what you're using for the Service Name. In my case, it wasn't launching the XPC and didn't show any errors or console logs.

1
votes

I had a similar error but the solution was just: clean, clean build folder, build.

Then, by magic, it worked as intended.