Skip to content

Commit

Permalink
feat(ios): implement forceShow (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiperes authored Aug 28, 2024
1 parent 3ae7226 commit cc9e9c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ All iOS boolean options can also be specified as `string`
| `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.critical` | `boolean` | `false` | Optional. If `true` the device can show up critical alerts. (Possible since iOS 12 with a special entitlement) **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.forceShow` | `boolean` | `false` | Optional. Controls the behavior of the notification when app is in foreground. If `true` and app is in foreground, it will show a notification in the notification drawer, the same way as when the app is in background (and `on('notification')` callback will be called. When the user clicks this notification, the Event "com.apple.UNNotificationDefaultActionIdentifier" will be called). When `false` and app is in foreground, the `on('notification')` callback will be called immediately. |

#### iOS GCM support

Expand Down
8 changes: 7 additions & 1 deletion src/ios/AppDelegate+notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
pushHandler.isInline = YES;
[pushHandler notificationReceived];

completionHandler(UNNotificationPresentationOptionNone);
UNNotificationPresentationOptions presentationOption = UNNotificationPresentationOptionNone;
if (@available(iOS 10, *)) {
if(pushHandler.forceShow) {
presentationOption = UNNotificationPresentationOptionAlert;
}
}
completionHandler(presentationOption);
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
Expand Down
2 changes: 2 additions & 0 deletions src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
NSString *notificationCallbackId;
NSString *callback;
BOOL clearBadge;
BOOL forceShow;

NSMutableDictionary *handlerObj;
void (^completionHandler)(UIBackgroundFetchResult);
Expand All @@ -53,6 +54,7 @@
@property BOOL isInline;
@property BOOL coldstart;
@property BOOL clearBadge;
@property BOOL forceShow;
@property (nonatomic, strong) NSMutableDictionary *handlerObj;

- (void)init:(CDVInvokedUrlCommand*)command;
Expand Down
10 changes: 10 additions & 0 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ @implementation PushPlugin : CDVPlugin
@synthesize notificationCallbackId;
@synthesize callback;
@synthesize clearBadge;
@synthesize forceShow;
@synthesize handlerObj;

@synthesize usesFCM;
Expand Down Expand Up @@ -181,6 +182,7 @@ - (void)init:(CDVInvokedUrlCommand*)command;
id alertArg = [iosOptions objectForKey:@"alert"];
id criticalArg = [iosOptions objectForKey:@"critical"];
id clearBadgeArg = [iosOptions objectForKey:@"clearBadge"];
id forceShowArg = [iosOptions objectForKey:@"forceShow"];

if (([badgeArg isKindOfClass:[NSString class]] && [badgeArg isEqualToString:@"true"]) || [badgeArg boolValue])
{
Expand Down Expand Up @@ -215,6 +217,14 @@ - (void)init:(CDVInvokedUrlCommand*)command;
}
NSLog(@"PushPlugin.register: clear badge is set to %d", clearBadge);

if (forceShowArg == nil || ([forceShowArg isKindOfClass:[NSString class]] && [forceShowArg isEqualToString:@"false"]) || ![forceShowArg boolValue]) {
NSLog(@"PushPlugin.register: setting forceShow to false");
forceShow = NO;
} else {
NSLog(@"PushPlugin.register: setting forceShow to true");
forceShow = YES;
}

isInline = NO;

NSLog(@"PushPlugin.register: better button setup");
Expand Down

0 comments on commit cc9e9c4

Please sign in to comment.