XPC Service Connection Invalidated Immediately on Launch


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?

Replies

Info.plist for the XPC service has ServiceType set to Bundled.

Where did you get that value from? The xpcservice.plist man page lists two values, and the default value, Application, is the one you want.

If you’re having problems with XPC service packaging, I recommend that you do this:

  1. Create a new project from the macOS > App template.

  2. Within that project, create a new target from the macOS > XPC Service template.

  3. Build the app.

  4. Look at how Xcode has set up the XPC service packaging.

Share and Enjoy

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

I literally have the same problem, I already did what Eskimo recommended and I have the same problem, it always tells me that the sandbox restricted something or that the connection simply cannot be made with the XPC service that I have!