XPC not creating any processes for XPC services
Asked Answered
S

3

5

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?

Stricken answered 30/10, 2012 at 19:45 Comment(1)
Hi, perhaps you can tell me how do I look at all the xpc services (is it done by launchctl or other command ? ) thanks !Illustrious
S
6

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

Stricken answered 30/10, 2012 at 19:45 Comment(2)
Any idea how to do it in XCode6?Janettjanetta
You can still change the code signing settings this way in Xcode 6.Stricken
F
2

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.

Frith answered 15/9, 2014 at 14:24 Comment(5)
Thanks! It's super-annoying that the default XPC service template doesn't get this right.Conklin
Hi, perhaps you can tell me how do I look at all the xpc services (is it done by launchctl or other command ? ) thanks !Illustrious
Is there any way to programmatically validate the name? It works now, but I'm worried that this will silently break in future refactorings, without much of a trace to debug.Brathwaite
@Brathwaite no i don't think you can validate. Typically these are services you control in your code base. So integration tests would be a good way to verify it worksFrith
@JessBowers Hmmm I'm having issues starting up an XPC service from my quicklook plugin target. I've validated that the service name matches the Bundle Identifier of the xpc service, and I've added a build step to copy the XPC service into MyQuickLookplugin.qlgenerate/contents/XPCServices. Do you know any troubleshooting steps I could take?Brathwaite
P
1

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

Then, by magic, it worked as intended.

Part answered 22/3, 2013 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.