Firebase刷新令牌

mKa*_*ane 5 objective-c ios firebase firebase-cloud-messaging

使用方法

[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]

我不太确定参数的要求是什么?什么是授权实体和行动?我也将苹果的APNS令牌传递给该方法吗?

Hea*_*Onn 7

  1. AUTHORIZED_ENTITY - 基本上它要求谷歌项目ID.它是数字的,如果您之前已经在项目中集成了GCM,那么它将是GCM_SENDER_ID(类似于"568520103762").检查您的Google-info.plist以查找它.
  2. 范围 - kFIRInstanceIDScopeFirebaseMessaging
  3. 选项 - @ {@"apns_token":deviceToken}(您将在didRegisterForRemoteNotifications方法中获取DeviceToken)
  4. HANDLER - 如果您已收到令牌或在此处捕获错误,请抓住令牌.如果token为nil,则在"tokenRefreshNotification"方法中等待令牌,如果令牌在[FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]中为nil,将自动调用该方法

例:

 if (![[FIRInstanceID instanceID] token]) {
    [[FIRInstanceID instanceID] tokenWithAuthorizedEntity:_gcmSenderId scope:kFIRInstanceIDScopeFirebaseMessaging options:_registrationOptions handler:^(NSString * _Nullable token, NSError * _Nullable error) {

        // Fetch the token or error
    }];

}
Run Code Online (Sandbox Code Playgroud)


Mah*_*eep 1

你可以这样做。

[[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);        
}];
Run Code Online (Sandbox Code Playgroud)