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

Force APNS | Added boolean ios init Option apnsForce to force apns | Updated docs as well #2736

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ All iOS boolean options can also be specified as `string`
| `ios.sound` | `boolean` | `false` | Optional. If `true` the device plays a sound on receipt of notification. **Note:** the value you set this option to the first time you call the init method will be how the application always acts. Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>`App Name`. This is normal iOS behaviour. |
| `ios.clearBadge` | `boolean` | `false` | Optional. If `true` the badge will be cleared on app startup. |
| `ios.categories` | `Object` | `{}` | Optional. The data required in order to enable Action Buttons for iOS. See [Action Buttons on iOS](https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#action-buttons-1) for more details. |
| `ios.apnsForce` | `boolean` | `false` | Optional. If `true` it will force APNS to be used even if GoogleServiceInfo.plist is present in the project. If `false` the default behaviour takes over i.e. FCM will be used if GoogleServiceInfo.plist file is present in your project and APNS will be used if GoogleServiceInfo.plist isn't present in your project |

#### iOS GCM support

Expand Down
8 changes: 7 additions & 1 deletion src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ - (void)init:(CDVInvokedUrlCommand*)command;
{
NSMutableDictionary* options = [command.arguments objectAtIndex:0];
NSMutableDictionary* iosOptions = [options objectForKey:@"ios"];
BOOL apnsForce = false;
id apnsForceArg = [iosOptions objectForKey:@"apnsForce"];
if (([apnsForceArg isKindOfClass:[NSString class]] && [apnsForceArg isEqualToString:@"true"]) || [apnsForceArg boolValue]) {
apnsForce = true;
NSLog(@"Push Plugin will now use APNS even if GoogleService-Info.plist is present");
}
id voipArg = [iosOptions objectForKey:@"voip"];
if (([voipArg isKindOfClass:[NSString class]] && [voipArg isEqualToString:@"true"]) || [voipArg boolValue]) {
[self.commandDelegate runInBackground:^ {
Expand Down Expand Up @@ -304,7 +310,7 @@ - (void)init:(CDVInvokedUrlCommand*)command;

// GCM options
[self setFcmSenderId: fcmSenderId];
if(isGcmEnabled && [[self fcmSenderId] length] > 0) {
if(isGcmEnabled && [[self fcmSenderId] length] > 0 && !apnsForce) {
NSLog(@"Using FCM Notification");
[self setUsesFCM: YES];
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down