xpc_connection_send_message_with_reply(_:_:_:_:)
Sends a message over the connection to the destination service and associates a handler to invoke when the remote service sends a reply message.
Declaration
func xpc_connection_send_message_with_reply(_ connection: xpc_connection_t, _ message: xpc_object_t, _ replyq: dispatch_queue_t?, _ handler: @escaping @Sendable (xpc_object_t) -> Void)Parameters
- connection:
The connection over which the message shall be sent.
- message:
The message to send. This must be a dictionary object.
- replyq:
The GCD queue to which the reply handler will be submitted. This may be a concurrent queue.
- handler:
The handler block to invoke when a reply to the message is received from the connection. If the remote service exits prematurely before the reply was received, the Xpc_error_connection_interrupted Swift.var error will be returned. If the connection went invalid before the message could be sent, the Xpc_error_connection_invalid Swift.var error will be returned.
Discussion
If the given GCD queue is a concurrent queue, XPC cannot guarantee that there will not be multiple reply handlers being invoked concurrently. XPC does not guarantee any ordering for the invocation of reply handers. So if multiple messages are waiting for replies and the connection goes invalid, there is no guarantee that the reply handlers will be invoked in FIFO order. Similarly, XPC does not guarantee that reply handlers will not run concurrently with the connection’s event handler in the case that the reply queue and the connection’s target queue are the same concurrent queue.