xpc_connection_create(_:_:)
Creates a new connection object.
Declaration
func xpc_connection_create(_ name: UnsafePointer<CChar>?, _ targetq: dispatch_queue_t?) -> xpc_connection_tParameters
- name:
If non-
NULL, the name of the service with which to connect. The returned connection will be a peer.If
NULL, an anonymous listener connection will be created. You can embed the ability to create new peer connections in an endpoint, which can be inserted into a message and sent to another process . - targetq:
The GCD queue to which the event handler block will be submitted. This parameter may be
NULL, in which case the connection’s target queue will be the default target queue oflibdispatch, defined asDISPATCH_TARGET_QUEUE_DEFAULT. The target queue may be changed later with a call to Xpc_connection_set_target_queue(_:_:).
Return Value
A new connection object. The caller is responsible for disposing of the returned object with xpc_release when it is no longer needed.
Discussion
This method will succeed even if the named service does not exist. This is because the XPC namespace is not queried for the service name until the first call to xpc_connection_resume(_:).
XPC connections, like dispatch sources, are returned in a suspended state, so you must call xpc_connection_resume(_:) in order to begin receiving events from the connection. Also like dispatch sources, connections must be resumed in order to be safely released. It is a programming error to release a suspended connection.