Fixed breaking didRefreshRegistrationToken problem (#221) * Fixed breaking didRefreshRegistrationToken problem * Trying to fix the cla problem * added newline for codestyle * added space for codestyle * moved logic of 'tokenRefreshNotification' to 'messaging didRefreshRegistrationToken' * formatting fix * updated changelog and pubspec * Added myself to AUTHORS file * firebaseMessagingPlugin: removed comment * removed unnecessary FIRMessaging disconnect
diff --git a/AUTHORS b/AUTHORS index efec478..ff28ac3 100644 --- a/AUTHORS +++ b/AUTHORS
@@ -5,3 +5,4 @@ Google Inc. German Saprykin <saprykin.h@gmail.com> +Benjamin Sauer <sauer.benjamin@gmail.com>
diff --git a/packages/firebase_messaging/CHANGELOG.md b/packages/firebase_messaging/CHANGELOG.md index 2c97092..c9c1e91 100644 --- a/packages/firebase_messaging/CHANGELOG.md +++ b/packages/firebase_messaging/CHANGELOG.md
@@ -1,3 +1,11 @@ +## 0.0.7 + +In FirebaseMessagingPlugin.m: +* moved logic from 'tokenRefreshNotification' to 'didRefreshRegistrationToken' +* removed 'tokenRefreshNotification' as well as observer registration +* removed 'connectToFcm' method and related calls +* removed unnecessary FIRMessaging disconnect + ## 0.0.6 * Change GMS dependency to 11.+
diff --git a/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m b/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m index 5866846..b0623f4 100644 --- a/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m +++ b/packages/firebase_messaging/ios/Classes/FirebaseMessagingPlugin.m
@@ -28,17 +28,14 @@ - (instancetype)initWithChannel:(FlutterMethodChannel *)channel { self = [super init]; + if (self) { _channel = channel; _resumingFromBackground = NO; if (![FIRApp defaultApp]) { [FIRApp configure]; } - [FIRMessaging messaging].remoteMessageDelegate = self; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(tokenRefreshNotification:) - name:kFIRInstanceIDTokenRefreshNotification - object:nil]; + [FIRMessaging messaging].delegate = self; } return self; } @@ -81,16 +78,6 @@ } } -- (void)tokenRefreshNotification:(NSNotification *)notification { - NSString *refreshedToken = [[FIRInstanceID instanceID] token]; - - // Connect to FCM since connection may have failed when attempted before - // having a token. - [self connectToFcm]; - - [_channel invokeMethod:@"onToken" arguments:refreshedToken]; -} - #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Receive data message on iOS 10 devices while app is in the foreground. - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage { @@ -98,22 +85,6 @@ } #endif -- (void)connectToFcm { - // Won't connect since there is no token - if (![[FIRInstanceID instanceID] token]) { - return; - } - - // Disconnect previous FCM connection if it exists. - [[FIRMessaging messaging] disconnect]; - - [[FIRMessaging messaging] connectWithCompletion:^(NSError *_Nullable error) { - if (error != nil) { - NSLog(@"Unable to connect to FCM. %@", error); - } - }]; -} - - (void)didReceiveRemoteNotification:(NSDictionary *)userInfo { if (_resumingFromBackground) { [_channel invokeMethod:@"onResume" arguments:userInfo]; @@ -133,13 +104,11 @@ } - (void)applicationDidEnterBackground:(UIApplication *)application { - [[FIRMessaging messaging] disconnect]; _resumingFromBackground = YES; } - (void)applicationDidBecomeActive:(UIApplication *)application { _resumingFromBackground = NO; - [self connectToFcm]; // Clears push notifications from the notification center, with the // side effect of resetting the badge count. We need to clear notifications // because otherwise the user could tap notifications in the notification @@ -180,4 +149,9 @@ [_channel invokeMethod:@"onIosSettingsRegistered" arguments:settingsDictionary]; } +- (void)messaging:(nonnull FIRMessaging *)messaging + didRefreshRegistrationToken:(nonnull NSString *)fcmToken { + [_channel invokeMethod:@"onToken" arguments:fcmToken]; +} + @end