-
-
Save fitomad/0b6ccf48cd7764937e55cde82806a4cd 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: NISessionDelegate | |
{ | |
/// La sesión no vale. | |
/// Hay que iniciar otra. | |
func session(_ session: NISession, didInvalidateWith error: Error) -> Void | |
{ | |
self.startNearbySession() | |
} | |
/// Se ha perdido la conexión con el otro dispositivo | |
/// La sesión no vale, tenemos que crear otra. | |
func session(_ session: NISession, didRemove nearbyObjects: [NINearbyObject], reason: NINearbyObject.RemovalReason) -> Void | |
{ | |
session.invalidate() | |
self.startNearbySession() | |
} | |
/// La app vuelve al primer plano | |
func sessionSuspensionEnded(_ session: NISession) -> Void | |
{ | |
guard let peerToken = self.peerToken else | |
{ | |
return | |
} | |
// Creamos la configuración... | |
let config = NINearbyPeerConfiguration(peerToken: peerToken) | |
// volvemos a levantar la sesión | |
self.nearbySession?.run(config) | |
self.shareTokenWithAllPeers() | |
} | |
/// La app pasa a background | |
func sessionWasSuspended(_ session: NISession) -> Void | |
{ | |
print("\(#function). Volveré... 🙋♂️") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment