According to the Apple Developer docs, XPC services that you as a developer can write must reside in your app’s bundle in My.app/Contents/XPC Services
. Your app can only connect to XPC services that reside there and those XPC services can only be connected to from the app whose bundle they reside in.
(Note that the XPC services Apple ships in its system frameworks work a bit differently: /System/Library/PrivateFrameworks/WebKit2.framework
contains XPC services that are used by any process that use the WebKit2 framework. But then again, the framework connects to that XPC service, not your app itself.)
That is probably the reason why you can’t connect to the XPC service if your subprocess’ binary is not in My.app/Contents/MacOS/
. I’m not sure, but that you can connect to the XPC service from an arbitrary binary that resides in MacOS
almost sounds like a bug. But I think it’s not because XPC services only work if the code signature is OK and placing an arbitrary binary in the MacOS
directory would break that code signature.
As for the dock icon: How are you spawning the subprocess? Using NSTask? Does the regular app itself use the XPC service? If not, is there any reason why the subprocess isn’t an app itself? That way the XPC service could be inside the subprocess’ /Contents/XPC Services
directory and everything should work OK.
Edit: Another solution that comes to mind: Don’t use XPC, but a separate process that talks via Distributed Objects to your subprocesses. Because that doesn’t require any special folder structure or something like that, you can place all auxiliary binaries wherever you want and can therefore avoid the Dock icon bouncing issue.