I have below demo code for XPC client:
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
});
I can connect to the xpc service and also send message successfully. The only issue here is that the reply message is always correctly received by event handler but in the reply block the object is always XPC_TYPE_ERROR.
I am little bit confused here because I thought the reply block should receive the correct reply object since it is explicitly declared for xpc_connection_send_message_with_reply but looks that's not the truth.
Can anyone explain how it happens and how to make sure the reply block can always get the correct reply?
Really appreciate for your reply.
Thanks!