-
-
Save fitomad/ab2840192d8a6941a028982d5a92af3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CercaViewModel: MCSessionDelegate | |
{ | |
... | |
/// | |
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) | |
{ | |
guard peerID.displayName == self.peerName else | |
{ | |
// Llegan datos de un cliente que no es | |
// con el que hemos iniciado la sesión | |
return | |
} | |
guard let discoveryToken = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NIDiscoveryToken.self, from: data) else | |
{ | |
fatalError("No se ha podido leer el token del otro dispositivo") | |
} | |
// Creamos la configuración... | |
let config = NINearbyPeerConfiguration(peerToken: discoveryToken) | |
// ...arrancamos la sesión de NearbyInteraction... | |
self.nearbySession?.run(config) | |
// ...y guardo el token del cliente por si tengo | |
// que reanudar mi sesión. | |
self.peerToken = discoveryToken | |
DispatchQueue.main.async { | |
self.isConnectionLost = false | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment