From a04e782db87b86bacc6a232fae38dcd8d203f5b6 Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Mon, 23 Apr 2018 16:50:15 -0700 Subject: Should always query the latest checkin info from InstanceID This fixes a bug that when we delete IID, IID refreshes new checkin info and FCM stops querying the checkin if checkin exists. And this causes FCM using staled checkin info and not able to receive data message. --- Firebase/Messaging/FIRMessagingClient.m | 26 ++++++++++---------------- Firebase/Messaging/FIRMessagingRegistrar.m | 6 +++--- 2 files changed, 13 insertions(+), 19 deletions(-) (limited to 'Firebase/Messaging') diff --git a/Firebase/Messaging/FIRMessagingClient.m b/Firebase/Messaging/FIRMessagingClient.m index d36778d..0bfb5a8 100644 --- a/Firebase/Messaging/FIRMessagingClient.m +++ b/Firebase/Messaging/FIRMessagingClient.m @@ -185,7 +185,6 @@ static NSUInteger FIRMessagingServerPort() { handler(error); }; - [self.registrar tryToLoadValidCheckinInfo]; [self.registrar updateSubscriptionToTopic:topic withToken:token options:options @@ -266,7 +265,6 @@ static NSUInteger FIRMessagingServerPort() { } self.lastDisconnectedTimestamp = FIRMessagingCurrentTimestampInMilliseconds(); self.connectHandler = handler; - [self.registrar tryToLoadValidCheckinInfo]; [self connect]; } @@ -279,21 +277,17 @@ static NSUInteger FIRMessagingServerPort() { } self.stayConnected = YES; - BOOL isRegistrationComplete = [self.registrar hasValidCheckinInfo]; - - if (!isRegistrationComplete) { - if (![self.registrar tryToLoadValidCheckinInfo]) { - // Checkin info is not available. This may be due to the checkin still being fetched. - if (self.connectHandler) { - NSError *error = [NSError errorWithFCMErrorCode:kFIRMessagingErrorCodeMissingDeviceID]; - self.connectHandler(error); - } - FIRMessagingLoggerDebug(kFIRMessagingMessageCodeClient009, - @"Failed to connect to MCS. No deviceID and secret found."); - // Return for now. If checkin is, in fact, retrieved, the - // |kFIRMessagingCheckinFetchedNotification| will be fired. - return; + if (![self.registrar tryToLoadValidCheckinInfo]) { + // Checkin info is not available. This may be due to the checkin still being fetched. + if (self.connectHandler) { + NSError *error = [NSError errorWithFCMErrorCode:kFIRMessagingErrorCodeMissingDeviceID]; + self.connectHandler(error); } + FIRMessagingLoggerDebug(kFIRMessagingMessageCodeClient009, + @"Failed to connect to MCS. No deviceID and secret found."); + // Return for now. If checkin is, in fact, retrieved, the + // |kFIRMessagingCheckinFetchedNotification| will be fired. + return; } [self setupConnectionAndConnect]; } diff --git a/Firebase/Messaging/FIRMessagingRegistrar.m b/Firebase/Messaging/FIRMessagingRegistrar.m index bb1e9ad..999666c 100644 --- a/Firebase/Messaging/FIRMessagingRegistrar.m +++ b/Firebase/Messaging/FIRMessagingRegistrar.m @@ -45,6 +45,8 @@ self = [super init]; if (self) { _checkinService = [[FIRMessagingCheckinService alloc] init]; + // TODO(chliangGoogle): Merge pubsubRegistrar with Registrar as it is hard to track how many + // checkinService instances by separating classes too often. _pubsubRegistrar = [[FIRMessagingPubSubRegistrar alloc] initWithCheckinService:_checkinService]; } return self; @@ -53,9 +55,7 @@ #pragma mark - Checkin - (BOOL)tryToLoadValidCheckinInfo { - if (![self.checkinService hasValidCheckinInfo]) { - [self.checkinService tryToLoadPrefetchedCheckinPreferences]; - } + [self.checkinService tryToLoadPrefetchedCheckinPreferences]; return [self.checkinService hasValidCheckinInfo]; } -- cgit v1.2.3