1

我正在开发一个 MacOS 应用程序,我试图将 IOSurface 从 XPC 服务发送到客户端应用程序(与 XPC 服务在同一个项目中),但我显然缺少一些东西。我收到以下错误:

Exception: Attempt to decode an xpc type but whitelist does not specify an XPC type '<no key>'.

整个错误文本如下:

2021-03-10 12:00:42.014421+0100 My Project[82813:1358040] [xpc.exceptions] 
  <NSXPCConnection: 0x600001aae6c0> connection on anonymousListener or serviceListener from pid 82827: 
  Exception caught during decoding of received selector publishNewFrame:, dropping incoming message.
Exception: Exception while decoding argument 0 (#2 of invocation):
Exception: Attempt to decode an xpc type but whitelist does not specify an XPC type '<no key>'.

我正在使用以下代码发送表面:

guard let connection = processConnection else {
    print("Process is not available")
    return
}

let process = connection.remoteObjectProxyWithErrorHandler {
    error in print("remote proxy error: ", error)
} as! MyProtocol
    
let XPCSurfaceRef = IOSurfaceCreateXPCObject(unsafeBitCast(surface, to: IOSurfaceRef.self))
process.publishNewFrame(XPCSurfaceRef)

议定书:

@objc public protocol MyProtocol: NSObjectProtocol {
  func publishNewFrame(_ XPCSurfaceRef: xpc_object_t)
}

在客户端进程上:

func publishNewFrame(_ XPCSurfaceRef: xpc_object_t) {
    let surfaceRef = IOSurfaceLookupFromXPCObject(XPCSurfaceRef)
}

我不知道如何继续。我不清楚我究竟需要将什么列入白名单,或者如何去做。原则上,IOSurface 是 XPC 中支持的类型,所以我知道它应该可以工作。

4

1 回答 1

1

当您启动连接时,您必须将传入类列入白名单。

例如:

let classSet: Set<AnyHashable> = [NSArray.self, NSDictionary.self]
connection.remoteObjectInterface?.setClasses( classSet, for: #selector(XpcServiceProtocol.article(pzn:withReply:)), argumentIndex: 0, ofReply: true)

有时找到正确的类有点棘手,因为 Swift 和 Objective-C 的类有时并不相同。您当然可以使用您的自定义类

于 2021-03-10T11:54:02.187 回答