<!--
{
  "availability" : [
    "iOS: 7.0.0 - 27.0.0",
    "iPadOS: 7.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.10.0 - 27.0.0",
    "tvOS: 10.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "MultipeerConnectivity",
  "identifier" : "/documentation/MultipeerConnectivity/MCNearbyServiceAdvertiserDelegate/advertiser(_:didReceiveInvitationFromPeer:withContext:invitationHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Multipeer Connectivity"
    ],
    "preciseIdentifier" : "c:objc(pl)MCNearbyServiceAdvertiserDelegate(im)advertiser:didReceiveInvitationFromPeer:withContext:invitationHandler:"
  },
  "title" : "advertiser(_:didReceiveInvitationFromPeer:withContext:invitationHandler:)"
}
-->

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

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

```
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 [Secure Coding Guide](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.

## Discussion

---

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)