Skip to content

Commit 922acc9

Browse files
authored
Return instance ID's token directly, if needed (#27)
Instance ID always provides FCM of the default token via NSNotification. However, if you access the `FCMToken` property too early (i.e. immediately after calling `[FIRApp configure]`), it was returning nil. This ensures that the default FCM token is always returned, if it is available.
1 parent 4c6bb5f commit 922acc9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Firebase/Messaging/FIRMessaging.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,12 @@ - (void)setAPNSToken:(NSData *)apnsToken type:(FIRMessagingAPNSTokenType)type {
471471
#pragma mark - FCM
472472

473473
- (NSString *)FCMToken {
474-
return self.defaultFcmToken;
474+
NSString *token = self.defaultFcmToken;
475+
if (!token) {
476+
// We may not have received it from Instance ID yet (via NSNotification), so extract it directly
477+
token = [self.instanceIDProxy token];
478+
}
479+
return token;
475480
}
476481

477482
- (void)retrieveFCMTokenForSenderID:(nonnull NSString *)senderID

0 commit comments

Comments
 (0)