Skip to content

Commit 75a7c2a

Browse files
[Messaging] - Validate APNS token in the configure flow (#10789)
1 parent 6d66e85 commit 75a7c2a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

FirebaseMessaging/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 10.6.0
2+
- [fixed] Configure flow validates existence of an APNS token before fetching an FCM token (#10742). This also addresses the scenario 1 mentioned in the comment - https://github.com/firebase/firebase-ios-sdk/issues/10679#issuecomment-1402776795
3+
14
# 10.5.0
25
- [fixed] Fixed a crash for strongSelf dereference (#10707).
36

FirebaseMessaging/Sources/FIRMessaging.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,13 @@ - (void)didCompleteConfigure {
239239
scope:kFIRMessagingDefaultTokenScope]
240240
.token;
241241
// When there is a cached token, do the token refresh.
242+
// Before fetching FCM token, confirm there is an APNS token to avoid validation error
243+
// This error is innocuous since we refetch after APNS token is set but it can seem alarming
242244
if (cachedToken) {
243245
// Clean up expired tokens by checking the token refresh policy.
244246
[self.installations installationIDWithCompletion:^(NSString *_Nullable identifier,
245247
NSError *_Nullable error) {
246-
if ([self.tokenManager checkTokenRefreshPolicyWithIID:identifier]) {
248+
if ([self.tokenManager checkTokenRefreshPolicyWithIID:identifier] && self.APNSToken) {
247249
// Default token is expired, fetch default token from server.
248250
[self retrieveFCMTokenForSenderID:self.tokenManager.fcmSenderID
249251
completion:^(NSString *_Nullable FCMToken, NSError *_Nullable error){
@@ -255,7 +257,7 @@ - (void)didCompleteConfigure {
255257
// TODO(chliangGoogle) Need to investigate better solution.
256258
[self updateDefaultFCMToken:self.FCMToken];
257259
}];
258-
} else if (self.isAutoInitEnabled) {
260+
} else if (self.isAutoInitEnabled && self.APNSToken) {
259261
// When there is no cached token, must check auto init is enabled.
260262
// If it's disabled, don't initiate token generation/refresh.
261263
// If no cache token and auto init is enabled, fetch a token from server.

0 commit comments

Comments
 (0)