Firebase Update Current

Using the method

[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]

I'm not quite sure what the parameters require? What is an authorized body and action? Also do I pass the APNS token from the apple to this method?

+4
source share
3 answers
  • AUTHORIZED_ENTITY - Basically it asks for the google project id. This is a numerical value, and if you already had GCM integrated into your project before, it would be GCM_SENDER_ID (something like "568520103762"). Check your Google-info.plist to find it.
  • SCOPE - kFIRInstanceIDScopeFirebaseMessaging
  • OPTIONS - @ {@ "apns_token": deviceToken} (you will get a DeviceToken in the didRegisterForRemoteNotifications method)
  • HANDLER - catch a token if you received a token or caught an error here. If the token is zero, then expect the token in the tokenRefreshNotification method, which will be called automatically if the token is zero [FIRInstanceID tokenWithAuthorizedEntity: scope: options: handler]

Example:

  if (![[FIRInstanceID instanceID] token]) { [[FIRInstanceID instanceID] tokenWithAuthorizedEntity:_gcmSenderId scope:kFIRInstanceIDScopeFirebaseMessaging options:_registrationOptions handler:^(NSString * _Nullable token, NSError * _Nullable error) { // Fetch the token or error }]; } 
+6
source

You can do it.

 [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; [[FIRInstanceID instanceID] tokenWithAuthorizedEntity:gcmSenderID scope:kFIRInstanceIDTokenRefreshNotification options:nil handler:^(NSString * _Nullable token, NSError * _Nullable error) { NSLog(@"GCM Registration token = %@",token); NSLog(@"GCM Registration error = %@",error); }]; 
+1
source

Swift version (based on @HeadOnn answer ):

 func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Messaging.messaging().setAPNSToken(deviceToken, type: .prod) // may be excess guard let plistPath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"), let options = FirebaseOptions(contentsOfFile: plistPath) else { return } InstanceID.instanceID().token(withAuthorizedEntity: options.gcmSenderID, scope: InstanceIDScopeFirebaseMessaging, options: ["apns_token": deviceToken]) { (token, error) in // handle token and error } } 
0
source

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


All Articles