---
title: "invitePeer(_:to:withContext:timeout:)"
framework: multipeerconnectivity
role: symbol
role_heading: Instance Method
path: "multipeerconnectivity/mcnearbyservicebrowser/invitepeer(_:to:withcontext:timeout:)"
---

# invitePeer(_:to:withContext:timeout:)

Invites a discovered peer to join a Multipeer Connectivity session.

## Declaration

```swift
func invitePeer(_ peerID: MCPeerID, to session: MCSession, withContext context: Data?, timeout: TimeInterval)
```

## Parameters

- `session`: The session you wish the invited peer to join.
- `context`: An arbitrary piece of data that is passed to the nearby peer. This can be used to provide further information to the user about the nature of the invitation. important: The nearby peer should treat any data it receives as potentially untrusted. To learn more about working with untrusted data, read https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Introduction.html#//apple_ref/doc/uid/TP40002415.
- `timeout`: The amount of time to wait for the peer to respond to the invitation. This timeout is measured in seconds, and must be a positive value. If a negative value or zero is specified, the default timeout (30 seconds) is used.
