我想发布CVImageBuffer
到以下Apple API:
func updateServiceInfo(_ serviceInfo: [String : NSCoding & NSObjectProtocol])
这是我的代码:
final class BufferClass: NSObject, NSSecureCoding {
static var supportsSecureCoding: Bool = true
let buffer: CVImageBuffer?
func encode(with coder: NSCoder) {
coder.encode(buffer, forKey: "buffer")
}
required init(coder decoder: NSCoder) {
buffer = decoder.decodeObject(forKey: "buffer") as! CVImageBuffer
}
init(buffer: CVImageBuffer) {
self.buffer = buffer
}
}
当我调用以下代码时:
let bufferClass = BufferClass(buffer: buffer)
updateServiceInfo(["buffer": bufferClass] )
我崩溃并显示以下消息:
Exception: *** -[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '__NSCFType').
*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '__NSCFType').