Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
fixed registration and removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored and macdonst committed May 4, 2017
1 parent 98c100b commit 6c1a557
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
@property(nonatomic, strong) NSNumber* gcmSandbox;
@property(nonatomic, strong) NSString *gcmSenderId;
@property(nonatomic, strong) NSDictionary *gcmRegistrationOptions;
@property(nonatomic, strong) void (^gcmRegistrationHandler) (NSString *registrationToken, NSError *error);
@property(nonatomic, strong) NSString *gcmRegistrationToken;
@property(nonatomic, strong) NSArray *gcmTopics;

Expand Down
53 changes: 24 additions & 29 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,32 @@ @implementation PushPlugin : CDVPlugin
@synthesize gcmSandbox;
@synthesize gcmSenderId;
@synthesize gcmRegistrationOptions;
@synthesize gcmRegistrationHandler;
@synthesize gcmRegistrationToken;
@synthesize gcmTopics;

-(void)initGCMRegistrationHandler;
-(void)initRegistration;
{
__weak __block PushPlugin *weakSelf = self;
gcmRegistrationHandler = ^(NSString *registrationToken, NSError *error){
if (registrationToken != nil) {
NSLog(@"GCM Registration Token: %@", registrationToken);
[weakSelf setGcmRegistrationToken: registrationToken];

id topics = [weakSelf gcmTopics];
if (topics != nil) {
for (NSString *topic in topics) {
NSLog(@"subscribe from topic: %@", topic);
id pubSub = [FIRInstanceID instanceID];
[pubSub subscribeToTopic:[NSString stringWithFormat:@"/topics/%@", topic]];
}
}

[weakSelf registerWithToken:registrationToken];
} else {
NSLog(@"Registration to GCM failed with error: %@", error.localizedDescription);
[weakSelf failWithMessage:self.callbackId withMsg:@"" withError:error];
NSString * registrationToken = [[FIRInstanceID instanceID] token];

if (registrationToken != nil) {
NSLog(@"FCM Registration Token: %@", registrationToken);
[self setGcmRegistrationToken: registrationToken];

id topics = [self gcmTopics];
if (topics != nil) {
for (NSString *topic in topics) {
NSLog(@"subscribe from topic: %@", topic);
id pubSub = [FIRInstanceID instanceID];
[pubSub subscribeToTopic:[NSString stringWithFormat:@"/topics/%@", topic]];
}
}
};

[self registerWithToken:registrationToken];
} else {
NSLog(@"FCM token is null");
}

}

// FCM refresh token
Expand All @@ -81,7 +80,7 @@ - (void)onTokenRefresh {
// A rotation of the registration tokens is happening, so the app needs to request a new token.
NSLog(@"The FCM registration token needs to be changed.");
[[FIRInstanceID instanceID] token];
[self gcmRegistrationHandler];
[self initRegistration];
#endif
}

Expand Down Expand Up @@ -345,8 +344,8 @@ - (void)init:(CDVInvokedUrlCommand*)command;
[self setUsesFCM: YES];
dispatch_async(dispatch_get_main_queue(), ^{
[FIRApp configure];
[self initRegistration];
});
[self initGCMRegistrationHandler];
} else {
NSLog(@"Using APNS Notification");
[self setUsesFCM:NO];
Expand All @@ -358,7 +357,7 @@ - (void)init:(CDVInvokedUrlCommand*)command;
(([gcmSandBoxArg isKindOfClass:[NSString class]] && [gcmSandBoxArg isEqualToString:@"true"]) ||
[gcmSandBoxArg boolValue]))
{
NSLog(@"Using GCM Sandbox");
NSLog(@"Using FCM Sandbox");
[self setGcmSandbox:@YES];
}

Expand Down Expand Up @@ -452,11 +451,7 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[results setValue:dev.model forKey:@"deviceModel"];
[results setValue:dev.systemVersion forKey:@"deviceSystemVersion"];

if([self usesFCM]) {

NSLog(@"token FCM %@",[[FIRInstanceID instanceID] token]);

} else {
if(![self usesFCM]) {
[self registerWithToken: token];
}
#endif
Expand Down

0 comments on commit 6c1a557

Please sign in to comment.