XPC Service Connection Invalidated Immediately on Launch

273 Views Asked by At

Development Environment:

  • Xcode Version: 14.3.1
  • macOS Ventura Version: 13.6.2
  • Architecture: Intel

I'm developing a macOS app with an accompanying XPC service and am encountering an issue where the XPC connection is immediately invalidated when trying to launch it. The error 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.}

What I've 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 component's installation directory is Content/XPCServices.
  • Code signing and entitlements have been verified for both the main app and the XPC service, and disabling the sandbox (as a temporary test) doesn't resolve the issue.
  • The main app and XPC service are part of the same App Group (with same identifier), and both have the App Sandbox capability.

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 (also checked the Console app). 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?

0

There are 0 best solutions below