in deployment/macos/diagnostic/SystemExtensionTester/TestSystemExtension/IPCConnection.swift [58:85]
func register(withExtension bundle: Bundle, completionHandler: @escaping (Bool) -> Void) {
guard currentConnection == nil else {
os_log("Already registered with the provider")
completionHandler(true)
return
}
let machServiceName = extensionMachServiceName(from: bundle)
let newConnection = NSXPCConnection(machServiceName: machServiceName, options: [])
// The remote object is the provider's IPCConnection instance.
newConnection.remoteObjectInterface = NSXPCInterface(with: ProviderCommunication.self)
currentConnection = newConnection
newConnection.resume()
guard let providerProxy = newConnection.remoteObjectProxyWithErrorHandler({ registerError in
os_log("Failed to register with the provider: %@", registerError.localizedDescription)
self.currentConnection?.invalidate()
self.currentConnection = nil
completionHandler(false)
}) as? ProviderCommunication else {
fatalError("Failed to create a remote object proxy for the provider")
}
providerProxy.register(completionHandler)
}