iOSアプリケーションでFirebase Cloud Messagingを実装しました。 1つのことを除いて、すべてがうまくいくように見えます。アプリから起動してFirebaseでデバイストークンをリフレッシュするのに約10秒かかります。Firebase InstanceIDトークンiOSデバイスのリフレッシュ遅延
私は、App委任でapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
メソッドにこのコードを追加しました:
[FIRApp configure];
//Add an observer for handling a token refresh callback.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshCallback:) name:kFIRInstanceIDTokenRefreshNotification object:nil];
そして、これはtokenRefreshCallback:
方法である:
- (void)tokenRefreshCallback:(NSNotification *)notification {
NSString *refreshedToken = [[FIRInstanceID instanceID] token];
NSLog(@"InstanceID token: %@", refreshedToken);
if ([[FIRInstanceID instanceID] token] != NULL) {
[[FIRMessaging messaging] subscribeToTopic:@"/topics/news"];
NSLog(@"Subscribed to news topic");
}
//Connect to FCM since connection may have failed when attempting before having a token
[self connectToFirebase];
}
そして、これはロガーの関連する部分である。
2016-10-13 14:36:23.844 My-App[1111] <Debug> [Firebase/Core][I-COR000001] Configuring the default app.
2016-10-13 14:36:26.492 My-App[1111:2222222] InstanceID token: (null)
2016-10-13 14:36:32.732 My-App[1111:2222222] InstanceID token: c1kmaskdmj...(the actual device token)
InstanceIDが(null)のときに
tokenRefreshCallback:
が呼び出されるのはなぜですか?なぜ実際のトークンが取得される前に約10秒かかりますか?