Development Environment:
Xcode Version: 14.3.1
macOS Ventura Version: 13.6.2
Architecture: Intel
I am developing a macOS app with an accompanying XPC service and am encountering an issue where the XPC connection is immediately invalidated upon trying to establish it. The error message received is:
Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.appname.macos.app-name-xpc was invalidated." UserInfo={NSDebugDescription=The connection to service named com.appname.macos.app-name-xpc was invalidated: failed at lookup with error 3 - No such process.}
Here's what I have verified so far:
The XPC service has the correct CFBundleIdentifier and is located within the Contents/XPCServices directory of my app's bundle.
Info.plist for the XPC service has ServiceType set to Bundled.
The XPC service target's Installation Directory is the default location for XPC services (@executable_path/../XPCServices).
Code signing and entitlements have been verified for both the main app and the XPC service, and disabling the sandbox doesn't resolve the issue.
The main app and XPC service are part of the same App Group, and both have the App Sandbox capability enabled.
Here's a snippet of the Swift code that establishes the XPC connection:
let xpcConnection = NSXPCConnection(serviceName: "com.appname.macos.app-name-xpc")
xpcConnection.remoteObjectInterface = NSXPCInterface(with: ServiceProtocol.self)
xpcConnection.resume()
And here's the ServiceProtocol for reference:
@objc public protocol ServiceProtocol: NSObjectProtocol {
@objc func executeUnixExecutable(arguments: [String], completionHandler: @escaping (ResultType) -> Void)
func interruptUnixExecutable()
func closeUnixExecutablePipes()
}
When I run the app, the connection is invalidated without any further details as to why. I'm not sure if I'm missing a configuration step or if there's an issue with my XPC service setup.
Has anyone experienced this issue or have suggestions on what else I can check to resolve this?