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

Commit

Permalink
Issue #689: Remove sender id from PushNotification init iOS options
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Jan 4, 2017
1 parent 1276d53 commit 54aa482
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
13 changes: 6 additions & 7 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ The following properties are used if you want use GCM on iOS.

Attribute | Type | Default | Description
--------- | ---- | ------- | -----------
`ios.senderID` | `string` | `undefined` (Native) | Maps to the project number in the Google Developer Console. Setting this uses GCM for notifications instead of native
`ios.gcmSandbox` | `boolean` | `false` | Whether to use prod or sandbox GCM setting. Defaults to false.
`ios.fcmSandbox` | `boolean` | `false` | Whether to use prod or sandbox GCM setting. Defaults to false.
`ios.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic.

##### How GCM on iOS works.
Expand All @@ -84,12 +83,12 @@ What happens is on the device side is that it registers with APNS, then that reg

When you send a message to GCM using that ID, what it does is look up the APNS registration ID on it's side and forward the message you sent to GCM on to APSN to deliver to your iOS device.

Make sure that the certificate you build with matches your `gcmSandbox` value.
Make sure that the certificate you build with matches your `fcmSandbox` value.

- If you build your app as development and set `gcmSandbox: false` it will fail.
- If you build your app as production and set `gcmSandbox: true` it will fail.
- If you build your app as development and set `gcmSandbox: true` but haven't uploaded the development certs to Google it will fail.
- If you build your app as production and set `gcmSandbox: false` but haven't uploaded the production certs to Google it will fail.
- If you build your app as development and set `fcmSandbox: false` it will fail.
- If you build your app as production and set `fcmSandbox: true` it will fail.
- If you build your app as development and set `fcmSandbox: true` but haven't uploaded the development certs to Google it will fail.
- If you build your app as production and set `fcmSandbox: false` but haven't uploaded the production certs to Google it will fail.

> Note: The integration between GCM and APNS is a bit finicky. Personally, I feel it is much better to send pushes to Android using GCM and pushes to iOS using APNS which this plugin does support.
Expand Down
12 changes: 6 additions & 6 deletions src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
- (void)didSendDataMessageWithID:(NSString *)messageID;
- (void)didDeleteMessagesOnServer;

// GCM Features
// FCM Features
@property(nonatomic, assign) BOOL usesFCM;
@property(nonatomic, strong) NSNumber* gcmSandbox;
@property(nonatomic, strong) NSString *gcmSenderId;
@property(nonatomic, strong) NSDictionary *gcmRegistrationOptions;
@property(nonatomic, strong) NSString *gcmRegistrationToken;
@property(nonatomic, strong) NSArray *gcmTopics;
@property(nonatomic, strong) NSNumber *fcmSandbox;
@property(nonatomic, strong) NSString *fcmSenderId;
@property(nonatomic, strong) NSDictionary *fcmRegistrationOptions;
@property(nonatomic, strong) NSString *fcmRegistrationToken;
@property(nonatomic, strong) NSArray *fcmTopics;

@end
43 changes: 26 additions & 17 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ @implementation PushPlugin : CDVPlugin
@synthesize handlerObj;

@synthesize usesFCM;
@synthesize gcmSandbox;
@synthesize gcmSenderId;
@synthesize gcmRegistrationOptions;
@synthesize gcmRegistrationToken;
@synthesize gcmTopics;
@synthesize fcmSandbox;
@synthesize fcmSenderId;
@synthesize fcmRegistrationOptions;
@synthesize fcmRegistrationToken;
@synthesize fcmTopics;

-(void)initRegistration;
{
Expand All @@ -57,9 +57,9 @@ -(void)initRegistration;

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

id topics = [self gcmTopics];
id topics = [self fcmTopics];
if (topics != nil) {
for (NSString *topic in topics) {
NSLog(@"subscribe from topic: %@", topic);
Expand Down Expand Up @@ -181,8 +181,8 @@ - (void)init:(CDVInvokedUrlCommand*)command;
NSMutableDictionary* options = [command.arguments objectAtIndex:0];
NSMutableDictionary* iosOptions = [options objectForKey:@"ios"];

NSArray* topics = [iosOptions objectForKey:@"topics"];
[self setGcmTopics:topics];
NSArray* topics = [iosOptions objectForKey:@"topics"];
[self setFcmTopics:topics];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
UIUserNotificationType UserNotificationTypes = UIUserNotificationTypeNone;
Expand Down Expand Up @@ -314,10 +314,19 @@ - (void)init:(CDVInvokedUrlCommand*)command;
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif


// Read GoogleService-Info.plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];

// Load the file content and read the data into arrays
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
fcmSenderId = [dict objectForKey:@"GCM_SENDER_ID"];

NSLog(@"FCM Sender ID %@", fcmSenderId);

// GCM options
[self setGcmSenderId: [iosOptions objectForKey:@"senderID"]];
NSLog(@"FCM Sender ID %@", gcmSenderId);
if([[self gcmSenderId] length] > 0) {
[self setFcmSenderId: fcmSenderId];
if([[self fcmSenderId] length] > 0) {
NSLog(@"Using FCM Notification");
[self setUsesFCM: YES];
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -328,15 +337,15 @@ - (void)init:(CDVInvokedUrlCommand*)command;
NSLog(@"Using APNS Notification");
[self setUsesFCM:NO];
}
id gcmSandBoxArg = [iosOptions objectForKey:@"gcmSandbox"];
id fcmSandboxArg = [iosOptions objectForKey:@"fcmSandbox"];

[self setGcmSandbox:@NO];
[self setFcmSandbox:@NO];
if ([self usesFCM] &&
(([gcmSandBoxArg isKindOfClass:[NSString class]] && [gcmSandBoxArg isEqualToString:@"true"]) ||
[gcmSandBoxArg boolValue]))
(([fcmSandboxArg isKindOfClass:[NSString class]] && [fcmSandboxArg isEqualToString:@"true"]) ||
[fcmSandboxArg boolValue]))
{
NSLog(@"Using FCM Sandbox");
[self setGcmSandbox:@YES];
[self setFcmSandbox:@YES];
}

if (notificationMessage) { // if there is a pending startup notification
Expand Down

0 comments on commit 54aa482

Please sign in to comment.