---
title: "advertiser(_:didReceiveInvitationFromPeer:withContext:invitationHandler:)"
framework: multipeerconnectivity
role: symbol
role_heading: Instance Method
path: "multipeerconnectivity/mcnearbyserviceadvertiserdelegate/advertiser(_:didreceiveinvitationfrompeer:withcontext:invitationhandler:)"
---

# advertiser(_:didReceiveInvitationFromPeer:withContext:invitationHandler:)

Called when an invitation to join a session is received from a nearby peer.

## Declaration

```swift
func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: Data?, invitationHandler: @escaping (Bool, MCSession?) -> Void)
```

## Parameters

- `advertiser`: The advertiser object that was invited to join the session.
- `peerID`: The peer ID of the nearby peer that invited your app to join the session.
- `context`: An arbitrary piece of data received from 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.
- `invitationHandler`: A block that your code must call to indicate whether the advertiser should accept or decline the invitation, and to provide a session with which to associate the peer that sent the invitation.
