From 084d078bf3da94cf6b70bfc938b790d8fdeb7bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Tue, 22 Nov 2016 20:40:54 +0100 Subject: [PATCH] Fix topic subscription and unsubscription on FCM --- src/ios/PushPlugin.m | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index e753ea00b..aa385cba6 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -129,25 +129,10 @@ - (void)subscribe:(CDVInvokedUrlCommand*)command; if (topic != nil) { NSLog(@"subscribe from topic: %@", topic); - id pubSub = [GCMPubSub sharedInstance]; - [pubSub subscribeWithToken: [self gcmRegistrationToken] - topic:[NSString stringWithFormat:@"/topics/%@", topic] - options:nil - handler:^void(NSError *error) { - if (error) { - if (error.code == 3001) { - NSLog(@"Already subscribed to %@", topic); - [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Already subscribed to %@", topic]]; - } else { - NSLog(@"Failed to subscribe to topic %@: %@", topic, error); - [self failWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Failed to subscribe to topic %@", topic] withError:error]; - } - } - else { - NSLog(@"Successfully subscribe to topic %@", topic); - [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Successfully subscribe to topic %@", topic]]; - } - }]; + id pubSub = [FIRInstanceID instanceID]; + [pubSub subscribeToTopic:[NSString stringWithFormat:@"/topics/%@", topic]]; + NSLog(@"Successfully subscribe to topic %@", topic); + [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Successfully subscribe to topic %@", topic]]; } else { NSLog(@"There is no topic to subscribe"); [self successWithMessage:command.callbackId withMsg:@"There is no topic to subscribe"]; @@ -160,19 +145,10 @@ - (void)unsubscribe:(CDVInvokedUrlCommand*)command; if (topic != nil) { NSLog(@"unsubscribe from topic: %@", topic); - id pubSub = [GCMPubSub sharedInstance]; - [pubSub unsubscribeWithToken: [self gcmRegistrationToken] - topic:[NSString stringWithFormat:@"/topics/%@", topic] - options:nil - handler:^void(NSError *error) { - if (error) { - NSLog(@"Failed to unsubscribe to topic %@: %@", topic, error); - [self failWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Failed to unsubscribe to topic %@", topic] withError:error]; - } else { - NSLog(@"Successfully unsubscribe to topic %@", topic); - [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Successfully unsubscribe to topic %@", topic]]; - } - }]; + id pubSub = [FIRInstanceID instanceID]; + [pubSub unsubscribeFromTopic:[NSString stringWithFormat:@"/topics/%@", topic]]; + NSLog(@"Successfully unsubscribe to topic %@", topic); + [self successWithMessage:command.callbackId withMsg:[NSString stringWithFormat:@"Successfully unsubscribe from topic %@", topic]]; } else { NSLog(@"There is no topic to unsubscribe"); [self successWithMessage:command.callbackId withMsg:@"There is no topic to unsubscribe"];