aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Messaging
diff options
context:
space:
mode:
authorGravatar Chen Liang <chliang@google.com>2018-04-23 16:50:15 -0700
committerGravatar GitHub <noreply@github.com>2018-04-23 16:50:15 -0700
commita04e782db87b86bacc6a232fae38dcd8d203f5b6 (patch)
treeadeef4074d5129633cdaa8096e3d1eac7a9be3fc /Firebase/Messaging
parent758b29aec4c2a76bd85f521ba652ceedd11313f1 (diff)
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.
Diffstat (limited to 'Firebase/Messaging')
-rw-r--r--Firebase/Messaging/FIRMessagingClient.m26
-rw-r--r--Firebase/Messaging/FIRMessagingRegistrar.m6
2 files changed, 13 insertions, 19 deletions
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];
}