To start, I recommend you read Technote 2083 Daemons and Agents. It somewhat out of date these days, but it defines a bunch of terms that I’m going to use without explaining.
launchd daemons and agents can publish services in the appropriate Mach bootstrap namespace (global for a launchd daemon, GUI per-session for a launchd agent unless you override that using the
LimitLoadToSessionType
property) via the
MachServices
property I mentioned earlier. Once a service is advertise the launchd job can use XPC (either the low-level C API or NSXPCConnection) to listen for connections to that service. Do this by passing the service name to
-[NSXPCListener initWithMachServiceName:]
.
Once that’s set up a client can connect to the service using
-[NSXPCConnection initWithMachServiceName:options:]
.
IMPORTANT If the service is registered in the global namespace (that is, you’re talking to a launchd daemon), pass in the
NSXPCConnectionPrivileged
flag to this routine. Pass in 0 if you’re talking to a launchd agent.
If you’re eventual goạl is to move this service to a launchd daemon then my recommendation is that you simply set up a launchd agent as described above and then go from there. There are lots of other things you can do if you have more complex requirements, but this is a good start.
ps Please drop me a line via email (my address is in my signature), making sure to quote this thread for context.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"