---
title: "cancelConnectPeer(_:)"
framework: multipeerconnectivity
role: symbol
role_heading: Instance Method
path: "multipeerconnectivity/mcsession/cancelconnectpeer(_:)"
---

# cancelConnectPeer(_:)

Cancels an attempt to connect to a peer.

## Declaration

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

## Parameters

- `peerID`: The ID of the nearby peer.

## Discussion

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:) 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 section in the overview of the MCSession class reference.

## See Also

### Managing Peers Manually

- [connectPeer(_:withNearbyConnectionData:)](multipeerconnectivity/mcsession/connectpeer(_:withnearbyconnectiondata:).md)
- [connectedPeers](multipeerconnectivity/mcsession/connectedpeers.md)
- [nearbyConnectionData(forPeer:withCompletionHandler:)](multipeerconnectivity/mcsession/nearbyconnectiondata(forpeer:withcompletionhandler:).md)
