---
title: "session(_:didReceiveCertificate:fromPeer:certificateHandler:)"
framework: multipeerconnectivity
role: symbol
role_heading: Instance Method
path: "multipeerconnectivity/mcsessiondelegate/session(_:didreceivecertificate:frompeer:certificatehandler:)"
---

# session(_:didReceiveCertificate:fromPeer:certificateHandler:)

Called to validate the client certificate provided by a peer when the connection is first established.

## Declaration

```swift
optional func session(_ session: MCSession, didReceiveCertificate certificate: [Any]?, fromPeer peerID: MCPeerID, certificateHandler: @escaping (Bool) -> Void)
```

## Parameters

- `session`: The session that the nearby peer wishes to join.
- `certificate`: A certificate chain, presented as an array of SecCertificateRef certificate objects. The first certificate in this chain is the peer’s certificate, which is derived from the identity that the peer provided when it called the doc://com.apple.multipeerconnectivity/documentation/MultipeerConnectivity/MCSession/init(peer:securityIdentity:encryptionPreference:) method. The other certificates are the (optional) additional chain certificates provided in that same array. If the nearby peer did not provide a security identity, then this parameter’s value is nil.
- `peerID`: The peer ID of the sender.
- `certificateHandler`: Your app should call this handler with a value of doc://com.apple.documentation/documentation/Swift/true if the nearby peer should be allowed to join the session, or doc://com.apple.documentation/documentation/Swift/false otherwise.

## Discussion

Discussion Your app should inspect the nearby peer’s certificate, and then should decide whether to trust that certificate. Upon making that determination, your app should call the provided certificateHandler block, passing either true (to trust the nearby peer) or false (to reject it). For information about validating certificates, read Cryptographic Services Guide. important: The multipeer connectivity framework makes no attempt to validate the peer-provided identity or certificates in any way. If your delegate does not implement this method, all certificates are accepted automatically.

## See Also

### MCSession Delegate Methods

- [session(_:didReceive:fromPeer:)](multipeerconnectivity/mcsessiondelegate/session(_:didreceive:frompeer:).md)
- [session(_:didStartReceivingResourceWithName:fromPeer:with:)](multipeerconnectivity/mcsessiondelegate/session(_:didstartreceivingresourcewithname:frompeer:with:).md)
- [session(_:didFinishReceivingResourceWithName:fromPeer:at:withError:)](multipeerconnectivity/mcsessiondelegate/session(_:didfinishreceivingresourcewithname:frompeer:at:witherror:).md)
- [session(_:didReceive:withName:fromPeer:)](multipeerconnectivity/mcsessiondelegate/session(_:didreceive:withname:frompeer:).md)
- [session(_:peer:didChange:)](multipeerconnectivity/mcsessiondelegate/session(_:peer:didchange:).md)
