What is the difference between FIRInstanceID.instanceID (). Token () and Messaging.messaging (). FcmToken?

I am using Firebase push notifications in my application. In one tutorial, I find that I get a token from Messaging.messaging().fcmToken and this SO question, which I find this way: FIRInstanceID.instanceID().token()

What is the difference between the two? My only goal is to be able to send my third-party guys to the token so that they can recognize me in the database for push notifications. Currently, my code that generates the token is this:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { if #available(iOS 10.0, *) { // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions, completionHandler: {_, _ in }) // For iOS 10 data message (sent via FCM Messaging.messaging().delegate = self } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } application.registerForRemoteNotifications() FirebaseApp.configure() let token = Messaging.messaging().fcmToken setFCM(token: token ?? "UNDEFINED") //a function that saves it in user defaults. print("FCM token: \(token ?? "")") return true } 
+5
source share
1 answer

A call to any of them should return the same registration token.

The difference is that FIRInstanceID contains only methods related to the registration token (for example, receiving and deleting a token), and Messaging (aka FIRMessaging - changing names ) generally provides more methods (for example, subscribing to topics, sending upstream messages )

+2
source

Source: https://habr.com/ru/post/1268952/


All Articles