I am building a Mac app that launch a GUI helper app and use XPC to communicate between them.
- Main app start a XPC Listener using
NSXPCListener(machServiceName: "group.com.mycompany.myapp.xpc")
- Launch the helper app
- 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!