I'm trying to use XPC communicate between a command line tool (launched from Terminal) and a macOS application. My code currently works when the app is launched from Xcode, but not if I launch the built app from the command line (open path-to-foo.app
) or if I try and distribute the packaged application (via "Development" distribution). Notably, the XPC works if the command line tool is launched from the terminal as long as the app itself is launched from Xcode.
I publish the XPC service using NSXPCListener(machServiceName: <team-identifier>.com.example.my-app.service)
and connect to it using NSXPCConnection(machServiceName: machServiceName)
. Both my command line tool and my main app identical "app group" entitlements for $(TeamIdentifierPrefix)com.example.my-app
and I verified the team identifier substitution was correct in both the app and command line tool after doing distributing for "App Store", exporting, unpacking the pkg
and running codesign
as described here: https://developer.apple.com/documentation/xcode/embedding-a-helper-tool-in-a-sandboxed-app
I found the answer in this post: https://forums.developer.apple.com/forums/thread/715338