session(_:didReceiveCertificate:fromPeer:certificateHandler:)
Called to validate the client certificate provided by a peer when the connection is first established.
Declaration
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 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 True if the nearby peer should be allowed to join the session, or False otherwise.
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.