aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Messaging
diff options
context:
space:
mode:
authorGravatar Riz <rsattar@gmail.com>2017-09-19 15:08:35 -0700
committerGravatar GitHub <noreply@github.com>2017-09-19 15:08:35 -0700
commitbc99b959e6e593adc3ec324c145c80c8f17934e7 (patch)
treeeef988ab0cbdc7f8f474af0a192444d0735fc5c5 /Firebase/Messaging
parent637bf879adc17b9609175499ed0b12e51b64ef7b (diff)
Fix app launch MCS connection issue (#290)
This fixes a bug in the automatic direct channel logic, where a failure to get checkin info from the Instance ID SDK was resulting in a non-retrying failure, causing the automatic connection logic to not retry connecting. A listener is added for a new notification that will be fired from Instance ID. When that notification is fired, `FIRMessagingClient` will re-attempt to connect. NOTE: The actual fix will not work until the Firebase InstanceID SDK is also updated.
Diffstat (limited to 'Firebase/Messaging')
-rw-r--r--Firebase/Messaging/FIRMessagingClient.m27
-rw-r--r--Firebase/Messaging/FIRMessagingConstants.h1
-rw-r--r--Firebase/Messaging/FIRMessagingConstants.m1
3 files changed, 26 insertions, 3 deletions
diff --git a/Firebase/Messaging/FIRMessagingClient.m b/Firebase/Messaging/FIRMessagingClient.m
index c01aecc..13e1775 100644
--- a/Firebase/Messaging/FIRMessagingClient.m
+++ b/Firebase/Messaging/FIRMessagingClient.m
@@ -17,6 +17,7 @@
#import "FIRMessagingClient.h"
#import "FIRMessagingConnection.h"
+#import "FIRMessagingConstants.h"
#import "FIRMessagingDataMessageManager.h"
#import "FIRMessagingDefines.h"
#import "FIRMessagingLogger.h"
@@ -117,6 +118,12 @@ static NSUInteger FIRMessagingServerPort() {
_rmq2Manager = rmq2Manager;
_registrar = [[FIRMessagingRegistrar alloc] init];
_connectionTimeoutInterval = kConnectTimeoutInterval;
+ // Listen for checkin fetch notifications, as connecting to MCS may have failed due to
+ // missing checkin info (while it was being fetched).
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(checkinFetched:)
+ name:kFIRMessagingCheckinFetchedNotification
+ object:nil];
}
return self;
}
@@ -135,6 +142,8 @@ static NSUInteger FIRMessagingServerPort() {
_FIRMessagingDevAssert(self.connection.state == kFIRMessagingConnectionNotConnected, @"Did not disconnect");
[NSObject cancelPreviousPerformRequestsWithTarget:self];
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)cancelAllRequests {
@@ -273,12 +282,15 @@ static NSUInteger FIRMessagingServerPort() {
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;
}
}
@@ -316,6 +328,14 @@ static NSUInteger FIRMessagingServerPort() {
self.connectHandler = nil;
}
+#pragma mark - Checkin Notification
+- (void)checkinFetched:(NSNotification *)notification {
+ // A failed checkin may have been the reason for the connection failure. Attempt a connection
+ // if the checkin fetched notification is fired.
+ if (self.stayConnected && !self.isConnected) {
+ [self connect];
+ }
+}
#pragma mark - Messages
@@ -465,9 +485,10 @@ static NSUInteger FIRMessagingServerPort() {
FIRMessagingConnectCompletionHandler handler = [self.connectHandler copy];
// disconnect before issuing a callback
[self disconnectWithTryToConnectLater:YES];
- NSError *error = [NSError errorWithDomain:@"No internet available, cannot connect to FIRMessaging"
- code:kFIRMessagingErrorCodeNetwork
- userInfo:nil];
+ NSError *error =
+ [NSError errorWithDomain:@"No internet available, cannot connect to FIRMessaging"
+ code:kFIRMessagingErrorCodeNetwork
+ userInfo:nil];
if (handler) {
handler(error);
self.connectHandler = nil;
diff --git a/Firebase/Messaging/FIRMessagingConstants.h b/Firebase/Messaging/FIRMessagingConstants.h
index 3112f7a..ad0d6c9 100644
--- a/Firebase/Messaging/FIRMessagingConstants.h
+++ b/Firebase/Messaging/FIRMessagingConstants.h
@@ -47,6 +47,7 @@ FOUNDATION_EXPORT NSString *const kFIRMessagingRemoteNotificationsProxyEnabledIn
FOUNDATION_EXPORT NSString *const kFIRMessagingApplicationSupportSubDirectory;
// Notifications
+FOUNDATION_EXPORT NSString *const kFIRMessagingCheckinFetchedNotification;
FOUNDATION_EXPORT NSString *const kFIRMessagingAPNSTokenNotification;
FOUNDATION_EXPORT NSString *const kFIRMessagingFCMTokenNotification;
FOUNDATION_EXPORT NSString *const kFIRMessagingInstanceIDTokenRefreshNotification __deprecated_msg("Use kFIRMessagingRegistrationTokenRefreshNotification instead");
diff --git a/Firebase/Messaging/FIRMessagingConstants.m b/Firebase/Messaging/FIRMessagingConstants.m
index 4e55ad2..8904cc5 100644
--- a/Firebase/Messaging/FIRMessagingConstants.m
+++ b/Firebase/Messaging/FIRMessagingConstants.m
@@ -41,6 +41,7 @@ NSString *const kFIRMessagingRemoteNotificationsProxyEnabledInfoPlistKey =
NSString *const kFIRMessagingApplicationSupportSubDirectory = @"Google/FirebaseMessaging";
// Notifications
+NSString *const kFIRMessagingCheckinFetchedNotification = @"com.google.gcm.notif-checkin-fetched";
NSString *const kFIRMessagingAPNSTokenNotification = @"com.firebase.iid.notif.apns-token";
NSString *const kFIRMessagingFCMTokenNotification = @"com.firebase.iid.notif.fcm-token";
NSString *const kFIRMessagingInstanceIDTokenRefreshNotification =