<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/xpc_session_t-10if0",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@T@xpc_session_t"
  },
  "title" : "xpc_session_t"
}
-->

# xpc_session_t

A C type that sends messages to a server process.

```
typealias xpc_session_t = OS_xpc_session
```

## Discussion

XPC sessions are stateful connections you use to send structured messages to a separate process. Once established, a session remains active until one side of the connection cancels it, at which point the system invalidates the connection. Unlike lower-level `xpc_connection` functions, the system makes no attempt to reestablish a connection or relaunch the service.

## Topics

### Creating a session

[`typealias xpc_session_t`](/documentation/XPC/xpc_session_t-49tiv)

[`func xpc_session_create_mach_service(UnsafePointer<CChar>, dispatch_queue_t?, xpc_session_create_flags_t, AutoreleasingUnsafeMutablePointer<xpc_rich_error_t?>?) -> (any OS_xpc_object)?`](/documentation/XPC/xpc_session_create_mach_service(_:_:_:_:))

[`func xpc_session_create_xpc_service(UnsafePointer<CChar>, dispatch_queue_t?, xpc_session_create_flags_t, AutoreleasingUnsafeMutablePointer<xpc_rich_error_t?>?) -> (any OS_xpc_object)?`](/documentation/XPC/xpc_session_create_xpc_service(_:_:_:_:))

[`struct xpc_session_create_flags_t`](/documentation/XPC/xpc_session_create_flags_t-swift.struct)

[`func xpc_session_copy_description(any OS_xpc_object) -> UnsafeMutablePointer<CChar>?`](/documentation/XPC/xpc_session_copy_description(_:))

[`func xpc_session_set_target_queue(any OS_xpc_object, dispatch_queue_t?)`](/documentation/XPC/xpc_session_set_target_queue(_:_:))

[`extern xpc_session_txpc_session_create_xpc_service(const char *name, dispatch_queue_t target_queue, xpc_session_create_flags_t flags, xpc_rich_error_t*error_out);`](/documentation/XPC/xpc_session_create_xpc_service)

Establishes a connection to an XPC service with the name you specify.

[`extern xpc_session_txpc_session_create_mach_service(const char *mach_service, dispatch_queue_t target_queue, xpc_session_create_flags_t flags, xpc_rich_error_t*error_out);`](/documentation/XPC/xpc_session_create_mach_service)

Establishes a connection to a launch agent or launch daemon with the name you specify.

[`typedef enum { ... } xpc_session_create_flags_t;`](/documentation/XPC/xpc_session_create_flags_t-c.enum)

Options that specify how to create inactive or privileged sessions.

[`extern void xpc_session_set_target_queue(xpc_session_t session, dispatch_queue_t target_queue);`](/documentation/XPC/xpc_session_set_target_queue)

Sets the target dispatch queue on an inactive session for processing messages.

[`extern char *xpc_session_copy_description(xpc_session_t session);`](/documentation/XPC/xpc_session_copy_description)

Copies the description string of a session.

### Managing life cycle

[`func xpc_session_activate(any OS_xpc_object, AutoreleasingUnsafeMutablePointer<xpc_rich_error_t?>?) -> Bool`](/documentation/XPC/xpc_session_activate(_:_:))

[`func xpc_session_cancel(any OS_xpc_object)`](/documentation/XPC/xpc_session_cancel(_:))

[`func xpc_session_set_cancel_handler(any OS_xpc_object, xpc_session_cancel_handler_t)`](/documentation/XPC/xpc_session_set_cancel_handler(_:_:))

[`func xpc_session_set_incoming_message_handler(any OS_xpc_object, xpc_session_incoming_message_handler_t)`](/documentation/XPC/xpc_session_set_incoming_message_handler(_:_:))

Sets a handler to receive incoming messages for a session.

[`typealias xpc_session_incoming_message_handler_t`](/documentation/XPC/xpc_session_incoming_message_handler_t-elj)

[`extern bool xpc_session_activate(xpc_session_t session, xpc_rich_error_t*error_out);`](/documentation/XPC/xpc_session_activate)

Activates a session so you can send messages.

[`extern void xpc_session_set_incoming_message_handler(xpc_session_t session, xpc_session_incoming_message_handler_t handler);`](/documentation/XPC/xpc_session_set_incoming_message_handler)

Sets a handler to receive incoming messages for a session.

[`typedef void (^)(NSObject<OS_xpc_object> *) xpc_session_incoming_message_handler_t;`](/documentation/XPC/xpc_session_incoming_message_handler_t-3eb2a)

A closure that receives an incoming message for a session.

[`extern void xpc_session_cancel(xpc_session_t session);`](/documentation/XPC/xpc_session_cancel)

Cancels a session, discarding any unsent messages.

[`extern void xpc_session_set_cancel_handler(xpc_session_t session, xpc_session_cancel_handler_t cancel_handler);`](/documentation/XPC/xpc_session_set_cancel_handler)

Sets a handler the session calls when it’s canceled.

[`typedef void (^)(NSObject<OS_xpc_object> *) xpc_session_cancel_handler_t;`](/documentation/XPC/xpc_session_cancel_handler_t-7y2lv)

A block the session calls when it’s canceled.

[`typealias xpc_session_cancel_handler_t`](/documentation/XPC/xpc_session_cancel_handler_t-65b6f)

### Sending messages

[`extern xpc_rich_error_txpc_session_send_message(xpc_session_t session, xpc_object_t message);`](/documentation/XPC/xpc_session_send_message)

Sends a message over the session to the destination service.

[`extern void xpc_session_send_message_with_reply_async(xpc_session_t session, xpc_object_t message, xpc_session_reply_handler_t reply_handler);`](/documentation/XPC/xpc_session_send_message_with_reply_async)

Sends a message asynchronously over the session to the destination service, calling a handler after receiving a reply.

[`typedef void (^)(NSObject<OS_xpc_object> *, NSObject<OS_xpc_object> *) xpc_session_reply_handler_t;`](/documentation/XPC/xpc_session_reply_handler_t-7kfe4)

A block that receives the reply to a message a session sends.

[`extern xpc_object_txpc_session_send_message_with_reply_sync(xpc_session_t session, xpc_object_t message, xpc_rich_error_t*error_out);`](/documentation/XPC/xpc_session_send_message_with_reply_sync)

Sends a message over the session to the destination service, blocking the caller until receiving a reply.

[`typealias xpc_rich_error_t`](/documentation/XPC/xpc_rich_error_t)

A type that describes an error, and whether you can retry the operation that experienced the error.

[`func xpc_rich_error_can_retry(xpc_rich_error_t) -> Bool`](/documentation/XPC/xpc_rich_error_can_retry(_:))

Returns a Boolean that indicates whether you can retry the operation that experienced an error.

[`func xpc_rich_error_copy_description(xpc_rich_error_t) -> UnsafeMutablePointer<CChar>?`](/documentation/XPC/xpc_rich_error_copy_description(_:))

Copies the string description of an error.

[`func xpc_session_send_message(any OS_xpc_object, xpc_object_t) -> xpc_rich_error_t?`](/documentation/XPC/xpc_session_send_message(_:_:))

[`func xpc_session_send_message_with_reply_async(any OS_xpc_object, xpc_object_t, xpc_session_reply_handler_t)`](/documentation/XPC/xpc_session_send_message_with_reply_async(_:_:_:))

[`typealias xpc_session_reply_handler_t`](/documentation/XPC/xpc_session_reply_handler_t-2hf7c)

[`func xpc_session_send_message_with_reply_sync(any OS_xpc_object, xpc_object_t, AutoreleasingUnsafeMutablePointer<xpc_rich_error_t?>?) -> xpc_object_t?`](/documentation/XPC/xpc_session_send_message_with_reply_sync(_:_:_:))

### Working with code signing

[`func xpc_session_set_peer_code_signing_requirement(xpc_session_t, UnsafePointer<CChar>) -> Int32`](/documentation/XPC/xpc_session_set_peer_code_signing_requirement(_:_:))



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)