<!--
{
  "availability" : [
    "iOS: 3.0.0 - 7.0.0",
    "iPadOS: 3.0.0 - 7.0.0",
    "macOS: 10.8.0 - 10.10.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "GameKit",
  "identifier" : "/documentation/GameKit/GKSession/cancelConnect(toPeer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKSession(im)cancelConnectToPeer:"
  },
  "title" : "cancelConnect(toPeer:)"
}
-->

# cancelConnect(toPeer:)

Cancels a pending request to connect to another iOS device.

```
func cancelConnect(toPeer peerID: String!)
```

## Parameters

`peerID`

The string identifying the peer you previously requested to connect to.

## Discussion

Your application previously called [`connect(toPeer:withTimeout:)`](/documentation/GameKit/GKSession/connect(toPeer:withTimeout:)) to create a connection to another iOS device. When your application cancels the connection attempt, both delegates’ [`session(_:connectionWithPeerFailed:withError:)`](/documentation/GameKit/GKSessionDelegate/session(_:connectionWithPeerFailed:withError:)) methods are called.

If your application already connected to the peer, your application should call [`disconnectFromAllPeers()`](/documentation/GameKit/GKSession/disconnectFromAllPeers()) instead.

---

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)