gpt4 book ai didi

xcode - XPC remoteObjectWithErrorHandler 不会抛出错误

转载 作者:行者123 更新时间:2023-12-05 07:51:11 27 4
gpt4 key购买 nike

我正在尝试检测是否通过错误处理程序安装了辅助工具,但错误 block 不会被执行,成功 block 也不会执行。当 helper 已经安装时,它工作正常。它只是在有错误时不捕获错误。在文档中总是执行这两个 block 之一

    if helperToolConnection == nil {
let connection = NSXPCConnection(machServiceName: "**bundle identifier**", options: NSXPCConnectionOptions.Privileged)
connection.remoteObjectInterface = NSXPCInterface(withProtocol: HelperProtocol.self)
connection.invalidationHandler = {
self.helperToolConnection = nil
}
connection.resume()
helperToolConnection = connection
}

let helper = helperToolConnection!.remoteObjectProxyWithErrorHandler() { error in
NSLog("Failed to connect: \(error)")
withReply(nil)
} as! HelperProtocol
helper.connectWithEndpointReply() { endpoint -> Void in
withReply(endpoint)
}

最佳答案

虽然我遇到了类似的问题并且还没有解决它,但我想我可以帮助解决你在这里遗漏的问题。

连接对象可能会在没有任何投诉的情况下创建,即使您没有安装 XPC 服务。它也可以顺利恢复。实际的连接尝试仅在您尝试发送第一条消息时发生

那么……你的

connection.invalidationHandler = {
self.helperToolConnection = nil
}

将在那时调用,使连接对象无效。出于这个原因,您的后续代码根本不执行任何操作 - 因为它的所有消息都发送到 nil。

为了验证我的理论 - 只需在使 invalidationHandler 中的 helperToolConnection 无效之前添加一个 NSLog(),然后重试。

关于xcode - XPC remoteObjectWithErrorHandler 不会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35303911/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com