Shared XPC service

Hello,

I want to build a developer tool and I have the following setup in mind. The tool consists of

  • a macOS app with a GUI
  • a background service (XPC service?) that performs the "heavy lifting"
  • and a framework ("Client.framework") that can be used by the developer to build customisations based on the background service. These customisations are supposed to be run as a command line tool, in the swift REPL or as a Playground.

Both the macOS GUI app and the Client.framework are kind of clients of the background service.

I did some experiments with an XPC service hosted by the macos app. During these experiements I was not able to connect to the XPC from the Client.framework (tried in the swift REPL, as a command line tool and a Playground). As soon as I try to open the connection to the XPC, the connection's invalidationHandler is called. Accesing the XPC from within the macOS GUI app ("host" app) works fine.

How can I implement this setup? Is an XPC service the right choice for my background service? Do I need to configure the XPC in a specific way to make it accessible from a framework used in the swift REPL, a command line tool or an Xcode Playground?

Thanks!

steven

I was not able to connect to the XPC from the Client.framework

That’s expected. An XPC Service embedded within an app is only usable by that app.

How can I implement this setup?

It depends (doesn’t it always :-). First things first, do you intend to ship this on the Mac App Store? Or independently, using Developer ID signing?

Oh, and what about the client app, the ones loading your framework? In this case it doesn’t really matter whether they’re targeting the Mac App Store during development, but it does matter if the final app needs to use your framework while deployed via the Mac App Store.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi Quinn,

I am planning to ship the macOS app via Developer ID signing.

The clients are not supposed to be shipped to the App Store - they are intended to be used during development only.

I did some more research and I think I should use a Launch Agent for the current user, if I am not mistaken. Then my question is, how I can ship this Launch Agent as part of a macOS App via Developer ID signing?

Best

Thanks for clarifying your requirements.

I did some more research and I think I should use a Launch Agent for the current user

That would work, but you may be better off with a Service Management login item. That can publish a named XPC listener that’s available to all code in the GUI login session [1]. It’s also easier for you to install and remove than a launchd agent.

For an example of this, see AppSandboxLoginItemXPCDemo.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Modulo sandbox restrictions on the client side.

Have you managed to follow on Quinns recommendation and access your "background" XPC-service from your Client.framework ?

I'm in a similar position and any hints can save me lots of time and suffering.

Shared XPC service
 
 
Q