1

有誰知道如何強制刷新FCM生成的註冊令牌?我最近才試圖將我的項目從GCM遷移到FCM。iOS和FCM:強制刷新令牌

在火力地堡網站上的文檔提到使用生成令牌:

// Get the default token 
// The first time you call this, the token may not be available, in which case 
// the SDK returns nil. 
// Once the token is fetched from the server, the SDK posts a token refresh 
// notification that you can listen for in order to access the new token. 

NSString *token = [[FIRInstanceID instanceID] token]; 

但它看起來像我只獲得當我打電話FIRInstanceID.instanceID().token()

回答

0

它可能會遲到,但任何人都可以參考我的回答如果是任何幫助。我同意@mKane,但我想添加更多的東西給他的答案。 如果您重置實例ID或刪除令牌,你可以可以調用

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

    // Fetch the token or error 
}]; 

如果令牌來零,然後等待在「tokenRefreshNotification」的方法,將被自動調用令牌,如果令牌是零在[ FIRInstanceID tokenWithAuthorizedEntity:scope:options:handler]。然後,您可以在「tokenRefreshNotification」方法中捕獲該標記並利用它。

有關如何使用此方法,請參閱我的回答here