<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.8.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSXPCListenerDelegate/listener(_:shouldAcceptNewConnection:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSXPCListenerDelegate(im)listener:shouldAcceptNewConnection:"
  },
  "title" : "listener(_:shouldAcceptNewConnection:)"
}
-->

# listener(_:shouldAcceptNewConnection:)

Accepts or rejects a new connection to the listener.

```
optional func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool
```

## Discussion

To accept the connection, first configure the connection if desired, then call [`resume()`](/documentation/Foundation/NSXPCConnection/resume()) on the new connection, then return <doc://com.apple.documentation/documentation/Swift/true>.

To reject the connect, return a value of <doc://com.apple.documentation/documentation/Swift/false>. This causes the connection object to be invalidated.

In this method, you can also set up properties on the connection object, such as its exported object and interfaces. Be sure to call [`resume()`](/documentation/Foundation/NSXPCConnection/resume()) when you are finished configuring the connection object and are ready for it to receive messages.

## See Also

  [Daemons and Services Programming Guide](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html#//apple_ref/doc/uid/10000172i)



---

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)