【发布时间】:2021-04-28 13:48:54
【问题描述】:
我有以下 XPC 客户端的演示代码:
xpc_connection_t _connection = xpc_connection_create_mach_service("mac.xpc.service.name",
NULL,
XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);
if (_connection == NULL) {
printf("connect daemon xpc service failed\n");
return;
}
xpc_connection_set_event_handler(_connection, ^(xpc_object_t obj) {
//event_handler
});
xpc_connection_resume(_connection);
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
//create message here
//...
xpc_connection_send_message_with_reply(_connection, message, NULL, ^(xpc_object_t object) {
//reply block
});
我可以连接到 xpc 服务并成功发送消息。 这里唯一的问题是事件处理程序始终正确接收到回复消息,但在回复块中,对象始终是 XPC_TYPE_ERROR。
我在这里有点困惑,因为我认为回复块应该接收正确的回复对象,因为它是为 xpc_connection_send_message_with_reply 显式声明的,但看起来事实并非如此。
谁能解释它是如何发生的以及如何确保回复块总是能得到正确的回复?
非常感谢您的回复。
谢谢!
【问题讨论】:
标签: macos eventhandler xpc