有没有办法立即生成FCM令牌?

时间:2017-02-04 10:20:57

标签: objective-c firebase firebase-cloud-messaging

FCM注册令牌需要10秒才能刷新并且非常不受欢迎。如何让它立即生效。我根据FCM文档生成这样的内容。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

[FIRApp configure];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) name:kFIRInstanceIDTokenRefreshNotification object:nil];
}

然后,

- (void)tokenRefreshNotification:(NSNotification *)notification {

NSString *refreshedToken = [[FIRInstanceID instanceID] token];
NSLog(@"InstanceID token: %@", refreshedToken);

// Connect to FCM since connection may have failed when attempted before having a token.

[self connectToFcm];

}

我正在使用FirebaseAppDelegateProxyEnabled。

提前致谢

1 个答案:

答案 0 :(得分:0)

FCM令牌是异步生成的。现在没有办法强制它们同步生成。您必须等待Firebase云消息传递呼叫tokenRefreshNotification回拨。

相关问题