NSXPCListener only working while Debugging `listener failed to activate: xpc_error=[1: Operation not permitted]`

I am building a Mac app that launch a GUI helper app and use XPC to communicate between them.

  1. Main app start a XPC Listener using NSXPCListener(machServiceName: "group.com.mycompany.myapp.xpc")
  2. Launch the helper app
  3. Helper app connect to the XPC service and listen command from main app.

What I observe is the app seems can start XPC listener while I run it via Xcode. If I run the app using TestFlight build, or via the compiled debug binary (same one that I use on Xcode), it cannot start the XPC service. Here is what I see in the Console:

[0x600000ef7570] activating connection: mach=true listener=true peer=false name=group.com.mycompany.myapp.xpc
[0x600000ef7570] listener failed to activate: xpc_error=[1: Operation not permitted]

Both main app and helper app are sandboxed and in the same App Group - if they were not, I cannot connect the helper app to main app. I can confirm the entitlement profiles did contain the app group.

If I start the main app via xcode, and then launch the helper app manually via Finder, the helper app can connect to the XPC and everything work.

It is not related to Release configuration, as the same binary work while I am debugging, but not when I open the binary manually.

For context, the main app is a Catalyst app, and helper app is an AppKit app. To start a XPC listener on Catalyst, I had do it in a AppKit bridge via bundle.

Given the app worked on Xcode, I believe this approach can work. I just cannot figure out why it only work while I am debugging.

Any pointer to debug this issue is greatly appreciated. Thanks!

After a bid of digging, it seems it is simply not possible to do this: you cannot simply setup a XPC service and expects another app, even under same app group, to communicate with it. That it work in Xcode is just a side effect of Xcode debugging.

It'll be helpful to know why XPC is not applicable in this context, but as suggested in this post XPC and App-to-App Communication the proper way is 1) not use XPC, 2) "XPC Rendezvous" using a third launchd job that only purpose is relay XPC listener endpoint.

To start a XPC listener on Catalyst, I had do it in a AppKit bridge via bundle.

I just wanna say up front that we don’t support folks loading Mac code into a Mac Catalyst process. It might work today, but we offer no guarantees that it’ll continue to work in the future.

I am building a Mac app that launch a GUI helper app and use XPC to communicate between them.

Is there a reason that your helper needs to be an app? Because most obvious path forward here is to make the helper an XPC service (.xpc), which is super easy to talk to from your main app.

Share and Enjoy

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

Yeah, except I'll need to use the helper to present native mac UI

NSXPCListener only working while Debugging `listener failed to activate: xpc_error=[1: Operation not permitted]`
 
 
Q