From 2e27c27eb52d9af671c1dd52f0de95b0b9203f41 Mon Sep 17 00:00:00 2001 From: Philipp Beck Date: Tue, 9 Feb 2021 08:58:03 +0100 Subject: [PATCH] breaking(ios): Remove fcm support for ios --- plugin.xml | 9 --- src/ios/PushPlugin.m | 64 ++------------- src/ios/PushPluginFCM.h | 25 ------ src/ios/PushPluginFCM.m | 147 ----------------------------------- src/ios/PushPluginSettings.h | 1 - src/ios/PushPluginSettings.m | 9 +-- 6 files changed, 8 insertions(+), 247 deletions(-) delete mode 100644 src/ios/PushPluginFCM.h delete mode 100644 src/ios/PushPluginFCM.m diff --git a/plugin.xml b/plugin.xml index 0ea81aa0d..6981b78d4 100755 --- a/plugin.xml +++ b/plugin.xml @@ -127,15 +127,6 @@ - - - - - - - - - diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 5fe886ebc..a6c1904c1 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -25,13 +25,10 @@ #import "PushPlugin.h" #import "PushPluginConstants.h" -#import "PushPluginFCM.h" #import "PushPluginSettings.h" @interface PushPlugin () -@property (nonatomic, strong) PushPluginFCM *pushPluginFCM; - @property (nonatomic, strong) NSDictionary *launchNotification; @property (nonatomic, strong) NSDictionary *notificationMessage; @property (nonatomic, strong) NSMutableDictionary *handlerObj; @@ -52,12 +49,6 @@ @implementation PushPlugin @synthesize callbackId; - (void)pluginInitialize { - self.pushPluginFCM = [[PushPluginFCM alloc] initWithGoogleServicePlist]; - - if([self.pushPluginFCM isFCMEnabled]) { - [self.pushPluginFCM configure:self.commandDelegate]; - } - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRegisterForRemoteNotificationsWithDeviceToken:) name:PluginDidRegisterForRemoteNotificationsWithDeviceToken @@ -90,50 +81,18 @@ - (void)pluginInitialize { } - (void)unregister:(CDVInvokedUrlCommand *)command { - NSArray* topics = [command argumentAtIndex:0]; - - if (topics != nil) { - [self.pushPluginFCM unsubscribeFromTopics:topics]; - } else { - [[UIApplication sharedApplication] unregisterForRemoteNotifications]; - [self successWithMessage:command.callbackId withMsg:@"unregistered"]; - } + [[UIApplication sharedApplication] unregisterForRemoteNotifications]; + [self successWithMessage:command.callbackId withMsg:@"unregistered"]; } - (void)subscribe:(CDVInvokedUrlCommand *)command { - if (!self.pushPluginFCM.isFCMEnabled) { - NSLog(@"[PushPlugin] The 'subscribe' API not allowed. FCM is not enabled."); - [self successWithMessage:command.callbackId withMsg:@"The 'subscribe' API not allowed. FCM is not enabled."]; - return; - } - - NSString* topic = [command argumentAtIndex:0]; - if (topic == nil) { - NSLog(@"[PushPlugin] There is no topic to subscribe"); - [self successWithMessage:command.callbackId withMsg:@"There is no topic to subscribe"]; - return; - } - - [self.pushPluginFCM subscribeToTopic:topic]; - [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Successfully subscribe to topic %@", topic]]; + NSLog(@"[PushPlugin] The 'subscribe' API not allowed. FCM is not enabled."); + [self successWithMessage:command.callbackId withMsg:@"The 'subscribe' API not allowed. FCM is not enabled."]; } - (void)unsubscribe:(CDVInvokedUrlCommand *)command { - if (!self.pushPluginFCM.isFCMEnabled) { - NSLog(@"[PushPlugin] The 'unsubscribe' API not allowed. FCM is not enabled."); - [self successWithMessage:command.callbackId withMsg:@"The 'unsubscribe' API not allowed. FCM is not enabled."]; - return; - } - - NSString* topic = [command argumentAtIndex:0]; - if (topic == nil) { - NSLog(@"[PushPlugin] There is no topic to unsubscribe from."); - [self successWithMessage:command.callbackId withMsg:@"There is no topic to unsubscribe from."]; - return; - } - - [self.pushPluginFCM unsubscribeFromTopic:topic]; - [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Successfully unsubscribe from topic %@", topic]]; + NSLog(@"[PushPlugin] The 'unsubscribe' API not allowed. FCM is not enabled."); + [self successWithMessage:command.callbackId withMsg:@"The 'unsubscribe' API not allowed. FCM is not enabled."]; } - (void)init:(CDVInvokedUrlCommand *)command { @@ -141,10 +100,6 @@ - (void)init:(CDVInvokedUrlCommand *)command { [[PushPluginSettings sharedInstance] updateSettingsWithOptions:[options objectForKey:@"ios"]]; PushPluginSettings *settings = [PushPluginSettings sharedInstance]; - if ([self.pushPluginFCM isFCMEnabled]) { - self.pushPluginFCM.callbackId = command.callbackId; - } - self.callbackId = command.callbackId; if ([settings voipEnabled]) { @@ -212,12 +167,7 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSNotification *)notif } NSLog(@"[PushPlugin] Successfully registered device for remote notification. (device token: %@)", deviceToken); - - if ([self.pushPluginFCM isFCMEnabled]) { - [self.pushPluginFCM configureTokens:deviceToken]; - } else { - [self registerWithToken:[self convertTokenToString:deviceToken]]; - } + [self registerWithToken:[self convertTokenToString:deviceToken]]; } - (NSString *)convertTokenToString:(NSData *)deviceToken { diff --git a/src/ios/PushPluginFCM.h b/src/ios/PushPluginFCM.h deleted file mode 100644 index ceb7830e8..000000000 --- a/src/ios/PushPluginFCM.h +++ /dev/null @@ -1,25 +0,0 @@ -#import -#import - -@import Firebase; - -NS_ASSUME_NONNULL_BEGIN - -@interface PushPluginFCM : NSObject - -@property (nonatomic, assign) BOOL isFCMEnabled; -@property (nonatomic, strong) NSString *callbackId; - -- (instancetype)initWithGoogleServicePlist; - -- (void)configure:(id )commandDelegate; -- (void)configureTokens:(NSData *)token; - -- (void)subscribeToTopic:(NSString *)topic; - -- (void)unsubscribeFromTopic:(NSString *)topic; -- (void)unsubscribeFromTopics:(NSArray *)topics; - -@end - -NS_ASSUME_NONNULL_END diff --git a/src/ios/PushPluginFCM.m b/src/ios/PushPluginFCM.m deleted file mode 100644 index 2038a1771..000000000 --- a/src/ios/PushPluginFCM.m +++ /dev/null @@ -1,147 +0,0 @@ -#import "PushPluginFCM.h" -#import "PushPluginSettings.h" - -@interface PushPluginFCM () - -@property (nonatomic, assign) BOOL isFCMRefreshTokenObserverAttached; -@property (nonatomic, weak) id commandDelegate; - -@end - -@implementation PushPluginFCM - -- (instancetype)initWithGoogleServicePlist { - self = [super init]; - if (self) { - NSString *googleServicePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]; - NSDictionary *googleServicePlist = [[NSDictionary alloc] initWithContentsOfFile:googleServicePath]; - - if (googleServicePlist != nil) { - NSString *fcmSenderId = [googleServicePlist objectForKey:@"GCM_SENDER_ID"]; - BOOL isGcmEnabled = [[googleServicePlist valueForKey:@"IS_GCM_ENABLED"] boolValue]; - - if (isGcmEnabled && fcmSenderId != nil) { - self.isFCMEnabled = YES; - NSLog(@"[PushPlugin] FCM is enabled and Sender ID is available."); - } else { - self.isFCMEnabled = NO; - NSLog(@"[PushPlugin] FCM is not enabled or Sender ID is missing."); - } - } else { - self.isFCMEnabled = NO; - NSLog(@"[PushPlugin] Could not locate GoogleService-Info.plist."); - } - } - return self; -} - -- (void)configure:(id )commandDelegate { - NSLog(@"[PushPlugin] Configuring Firebase App for FCM"); - if(![FIRApp defaultApp]) { - [FIRApp configure]; - } - - self.commandDelegate = commandDelegate; -} - -- (void)configureTokens:(NSData *)token { - NSLog(@"[PushPlugin] Setting APNS Token for Firebase App"); - [[FIRMessaging messaging] setAPNSToken:token]; - - [self setFCMTokenWithCompletion]; -} - -- (void)setRefreshedFCMToken { - NSLog(@"[PushPlugin] FIR has triggered a token refresh."); - [self setFCMTokenWithCompletion]; -} - -- (void)setFCMTokenWithCompletion { - #if TARGET_IPHONE_SIMULATOR - NSLog(@"[PushPlugin] Detected simulator. Will register an FCM token but pushing to simulator is not possible."); - #endif - - __weak __typeof(self) weakSelf = self; - [[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) { - if (error != nil) { - NSLog(@"[PushPlugin] Error getting FCM registration token: %@", error); - } else { - NSLog(@"[PushPlugin] FCM registration token: %@", token); - [weakSelf subscribeToTopics:[PushPluginSettings sharedInstance].fcmTopics]; - [weakSelf sendRegistrationPluginResult:token]; - [weakSelf attachFCMTokenRefreshObserver]; - } - }]; -} - -- (void)sendRegistrationPluginResult:(NSString *)token { - NSMutableDictionary* message = [NSMutableDictionary dictionaryWithCapacity:2]; - [message setObject:token forKey:@"registrationId"]; - [message setObject:@"FCM" forKey:@"registrationType"]; - - // Send result to trigger 'registration' event but keep callback - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:message]; - [pluginResult setKeepCallbackAsBool:YES]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; -} - -- (void)attachFCMTokenRefreshObserver { - if (self.isFCMRefreshTokenObserverAttached) { - NSLog(@"[PushPlugin] FCM token refresh observer was already attached."); - return; - } - - NSLog(@"[PushPlugin] Attaching FCM token refresh observer."); - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setRefreshedFCMToken) - name:FIRMessagingRegistrationTokenRefreshedNotification - object:nil]; - - self.isFCMRefreshTokenObserverAttached = YES; -} - -- (void)subscribeToTopics:(NSArray *)topics { - if(!topics) { - NSLog(@"[PushPlugin] There are no topics to subscribe to."); - return; - } - - for (NSString *topic in topics) { - [self subscribeToTopic:topic]; - } -} - -- (void)subscribeToTopic:(NSString *)topic { - if (!topic) { - NSLog(@"[PushPlugin] There is no topic to subscribe to."); - return; - } - - NSLog(@"[PushPlugin] Subscribing to topic: %@", topic); - [[FIRMessaging messaging] subscribeToTopic:topic]; - NSLog(@"[PushPlugin] Successfully subscribed to topic %@", topic); -} - -- (void)unsubscribeFromTopics:(NSArray *)topics { - if(!topics) { - NSLog(@"[PushPlugin] There are no topics to unsubscribe from."); - return; - } - - for (NSString *topic in topics) { - [self unsubscribeFromTopic:topic]; - } -} - -- (void)unsubscribeFromTopic:(NSString *)topic { - if (!topic) { - NSLog(@"[PushPlugin] There is no topic to unsubscribe from."); - return; - } - - NSLog(@"[PushPlugin] Unsubscribing from topic: %@", topic); - [[FIRMessaging messaging] unsubscribeFromTopic:topic]; - NSLog(@"[PushPlugin] Successfully unsubscribed from topic %@", topic); -} - -@end diff --git a/src/ios/PushPluginSettings.h b/src/ios/PushPluginSettings.h index 0ac12cff1..4463c915e 100644 --- a/src/ios/PushPluginSettings.h +++ b/src/ios/PushPluginSettings.h @@ -18,7 +18,6 @@ @property (nonatomic, readonly) BOOL forceShowEnabled; @property (nonatomic, readonly) BOOL voipEnabled; -@property (nonatomic, readonly, strong) NSArray *fcmTopics; @property (nonatomic, readonly, strong) NSSet *categories; + (instancetype)sharedInstance; diff --git a/src/ios/PushPluginSettings.m b/src/ios/PushPluginSettings.m index 037ddc9f9..2a505261f 100644 --- a/src/ios/PushPluginSettings.m +++ b/src/ios/PushPluginSettings.m @@ -35,7 +35,6 @@ - (instancetype)initWithDefaults { @"clearBadge" : @(NO), @"forceShow" : @(NO), @"voip" : @(NO), - @"fcmTopics" : @[], @"categories" : [NSSet set] } mutableCopy]; } @@ -46,9 +45,7 @@ - (void)updateSettingsWithOptions:(NSDictionary *)options { for (NSString *key in options) { if ([self.settingsDictionary objectForKey:key]) { // Overrides the default setting if defined and apply the correct formatting based on the key. - if ([key isEqualToString:@"fcmTopics"]) { - self.settingsDictionary[key] = [self parseArrayOption:key fromOptions:options withDefault:nil]; - } else if ([key isEqualToString:@"categories"]) { + if ([key isEqualToString:@"categories"]) { self.settingsDictionary[key] = [self parseCategoriesFromOptions:options[key]]; } else { self.settingsDictionary[key] = @([self parseOption:key fromOptions:options withDefault:NO]); @@ -168,10 +165,6 @@ - (BOOL)voipEnabled { return [self.settingsDictionary[@"voip"] boolValue]; } -- (NSArray *)fcmTopics { - return self.settingsDictionary[@"fcmTopics"]; -} - - (NSSet *)categories { return self.settingsDictionary[@"categories"]; }