Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.