send(message:replyHandler:)
Sends a message asynchronously over the session to the destination service, calling a closure after receiving a reply.
Declaration
@preconcurrency func send(message: XPCDictionary, replyHandler: @escaping @Sendable (Result<XPCDictionary, XPCRichError>) -> Void)Parameters
- message:
A dictionary object that contains the message to send.
- replyHandler:
A closure the session invokes when it receives a reply. The closure takes a result parameter that contains either the reply that the destination sent back or an error describing a failure.
Discussion
Sessions send messages serially in a first-in, first-out (FIFO) order. This method is safe to call from multiple dispatch queues. The session can’t indicate whether the message delivery is successful or not. While the session may successfully enqueue the message at the remote end of the connection, there’s no guarantee about when the destination dequeues the message and invokes the receiving session’s handler.
If the session fails to send the message, this method throws an error that contains details about the failure.
If the system tears down the session’s connection before receiving a reply, it invokes replyHandler with a result containing an XPCRichError describing the failure. For example, the remote service exits prematurely before sending a reply.