Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPC not creating any processes for XPC services

Tags:

ipc

xpc

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?

like image 404
James Bedford Avatar asked Oct 30 '12 19:10

James Bedford


People also ask

What is XPC services on Mac?

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.

What is XPC listener?

XPC Services A listener that waits for new incoming connections, configures them, and accepts or rejects them. protocol NSXPCListenerDelegate.

What is Nsxpcconnection H?

A bidirectional communication channel between two processes.


3 Answers

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

like image 51
James Bedford Avatar answered Oct 11 '22 09:10

James Bedford


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.

like image 24
Jess Bowers Avatar answered Oct 11 '22 07:10

Jess Bowers


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

Then, by magic, it worked as intended.

like image 1
Olof_t Avatar answered Oct 11 '22 09:10

Olof_t