<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/XPCSession/init(xpcService:targetQueue:options:requirement:cancellationHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "s:3XPC10XPCSessionC10xpcService11targetQueue7options11requirement19cancellationHandlerACSS_So17OS_dispatch_queueCSgAC21InitializationOptionsVAA18XPCPeerRequirementVyAA12XPCRichErrorVcSgtKcfc"
  },
  "title" : "init(xpcService:targetQueue:options:requirement:cancellationHandler:)"
}
-->

# init(xpcService:targetQueue:options:requirement:cancellationHandler:)

Creates a new session object representing a connection to the named
service, and requires that the session peer has the specified
requirement.

```
@preconcurrency convenience init(xpcService: String, targetQueue: DispatchQueue? = nil, options: XPCSession.InitializationOptions = .none, requirement: XPCPeerRequirement, cancellationHandler: (@Sendable (XPCRichError) -> Void)? = nil) throws
```

## Discussion

- requirement: The requirement the peer must have

> Note: All messages received on this session will be checked to ensure
> that they come from a peer who satisfies the requirement. When a reply
> is expected on the session and the peer does not satisfy the
> requirement, the session will be canceled and user’s cancelation
> handler will be invoked with `XPCRichError` describing the code signing
> error.

---

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)