Eventually it would be part of launchctl based daemon
In that case you should be careful about starting with an XPC Service. It’s fine to use that to play around with XPC (although there is a better way to do that; see below) but there are significant differences between the way you package an XPC Service and a launchd daemon that vends a named XPC listener:
In both cases there are limits to how your run your program:
-
An XPC Service can only be embedded in an app (or appex) and is automatically started by the system when the container app attempts to connect.
-
A launchd daemon must be loaded into launchd, typically by installing a launchd property list file. Once loaded, launchd starts the daemon when a client attempts to connect to one of its services.
I can get it work under Xcode interactive debugger.
Right. Xcode has special sauce that allows it to debug XPC Services. This does not apply to launchd daemons.
But from command line I get the illegal instruction.
Right. You can’t just run an XPC Service from the command line. It has to be launched in response to a connection from its container app.
Similarly, you can’t run a launchd daemon from the command line. Well, you can, but it’ll fail when it tries to check in with launchd.
My advice:
-
If you want to play around with XPC, just to get a feel for how the API works, use a loopback service. See this post for info on that.
-
When you eventually switch to using a launchd daemon, you must load it into launchd. Running it from Xcode isn’t supported.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"