Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created June 25, 2020 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/dbe41c5e3bae20482014e16e6c4002f2 to your computer and use it in GitHub Desktop.
Save fitomad/dbe41c5e3bae20482014e16e6c4002f2 to your computer and use it in GitHub Desktop.
/**
Desde aquí compartimos nuestro token de
`NearbyInteraction` con los otros dispositivos.
*/
private func shareTokenWithAllPeers() -> Void
{
guard let token = nearbySession?.discoveryToken,
let multipeerSession = self.multipeerSession,
let encodedData = try? NSKeyedArchiver.archivedData(withRootObject: token, requiringSecureCoding: true)
else
{
fatalError("Ese token no se puede codificar. 😭")
}
do
{
try self.multipeerSession?.send(encodedData,
toPeers: multipeerSession.connectedPeers,
with: .reliable)
}
catch let error
{
print("No se puede enviar el token a los dispositivos. \(error.localizedDescription)")
}
// Ya hemos compartido el token.
self.sharedTokenWithPeer = true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment