Guest User

Untitled

a guest
Jan 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. let instance = FIRInstanceID.instanceID()
  2. _ = FIRInstanceID.delete(instance)
  3. FIRInstanceID.instanceID().delete { (err:Error?) in
  4. if err != nil{
  5. print(err.debugDescription);
  6. } else {
  7. print("Token Deleted");
  8. }
  9. }
  10.  
  11. if let token = FIRInstanceID.instanceID().token() {
  12. print("Token (token) fetched");
  13. } else {
  14. print("Unable to fetch token");
  15. }
  16.  
  17. FIRMessaging.messaging().connect { (error) in
  18. if (error != nil) {
  19. print("Error connecting to FCM. (error.debugDescription)")
  20. } else {
  21. print("Connected to FCM.")
  22. }
  23. }
  24.  
  25. func registerFirebaseToken() {
  26. if let token = InstanceID.instanceID().token() {
  27. print("FIREBASE: Token (token) fetched")
  28. } else {
  29. print("FIREBASE: Unable to fetch token");
  30. }
  31.  
  32. Messaging.messaging().shouldEstablishDirectChannel = true
  33. }
  34.  
  35. func unregisterFirebaseToken(completion: @escaping (Bool)->()) {
  36. // Delete the Firebase instance ID
  37. InstanceID.instanceID().deleteID { (error) in
  38. if error != nil{
  39. print("FIREBASE: ", error.debugDescription);
  40. completion(false)
  41. } else {
  42. print("FIREBASE: Token Deleted");
  43. completion(true)
  44. }
  45. }
  46. }
  47.  
  48. extension AppDelegate: MessagingDelegate {
  49. func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
  50. registerFirebaseToken()
  51. }
  52. }
Add Comment
Please, Sign In to add comment