<!--
{
  "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/connectPeer(_:withNearbyConnectionData:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Multipeer Connectivity",
      "MultipeerConnectivity"
    ],
    "preciseIdentifier" : "c:objc(cs)MCSession(im)connectPeer:withNearbyConnectionData:"
  },
  "title" : "connectPeer(_:withNearbyConnectionData:)"
}
-->

# connectPeer(_:withNearbyConnectionData:)

Call this method to connect a peer to the session when using your own service discovery code instead of an  `MCNearbyServiceBrowser` or `MCBrowserViewController` object.

```
func connectPeer(_ peerID: MCPeerID, withNearbyConnectionData data: Data)
```

## Parameters

`peerID`

The peer ID object obtained from the nearby peer.

`data`

The connection data object obtained from the nearby peer.

## Discussion

Call this method to connect to peers when you are using your own service discovery code instead of an `MCNearbyServiceBrowser` or `MCBrowserViewController` object. 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)