<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MultipeerConnectivity",
  "identifier" : "/documentation/MultipeerConnectivity/MCSession/cancelConnectPeer(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Multipeer Connectivity",
      "MultipeerConnectivity"
    ],
    "preciseIdentifier" : "c:objc(cs)MCSession(im)cancelConnectPeer:"
  },
  "title" : "cancelConnectPeer(_:)"
}
-->

# cancelConnectPeer(_:)

Cancels an attempt to connect to a peer.

```
func cancelConnectPeer(_ peerID: MCPeerID)
```

## Parameters

`peerID`

The ID of the nearby peer.

## Discussion

Call this method to cancel connections to peers when you are using your own service discovery code instead of an `MCNearbyServiceBrowser` or `MCBrowserViewController` object. It should be called in two situations:

- If your app calls [`connectPeer(_:withNearbyConnectionData:)`](/documentation/MultipeerConnectivity/MCSession/connectPeer(_:withNearbyConnectionData:)) and later needs to cancel the connection attempt
- If your app has obtained nearby connection data for a peer but you decide not to connect to the peer

For more information, see the [`Managing Peers Manually`](/documentation/MultipeerConnectivity/MCSession#Managing-Peers-Manually) section in the overview of the `MCSession` class reference.

---

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)