Firebase Refresh Token

2019-02-24 19:51发布

Using the method

[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]

Im not quite sure what the parameters are calling for? What is the authorized entity and action? Also do I pass in the APNS token from apple to that method?

2条回答
太酷不给撩
2楼-- · 2019-02-24 20:14
  1. AUTHORIZED_ENTITY - Basically it asks for the google project id. It is numeric, and if you already had GCM integrated in your project before, it would be GCM_SENDER_ID (something like "568520103762"). Check your Google-info.plist to find it.
  2. SCOPE - kFIRInstanceIDScopeFirebaseMessaging
  3. OPTIONS - @{@"apns_token": deviceToken} (You will get DeviceToken in didRegisterForRemoteNotifications method)
  4. HANDLER - Catch token if you have received token or catch the error here. If token comes nil, then wait for token in "tokenRefreshNotification" method, which will be called automatically if the token is nil in [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
    }];

}
查看更多
闹够了就滚
3楼-- · 2019-02-24 20:20

You can do like this.

[[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);        
}];
查看更多
登录 后发表回答