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?
The XPC Services API provides a lightweight mechanism for basic interprocess communication at the libSystem level. It allows you to create lightweight helper tools, called XPC services, that perform work on behalf of your app.
XPC Services A listener that waits for new incoming connections, configures them, and accepts or rejects them. protocol NSXPCListenerDelegate.
A bidirectional communication channel between two processes.
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.
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.
I had a similar error but the solution was just: clean, clean build folder, build.
Then, by magic, it worked as intended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With