diff --git a/docs/API.md b/docs/API.md index 17cd98334..445ebb339 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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 diff --git a/src/ios/AppDelegate+notification.m b/src/ios/AppDelegate+notification.m index 895b93cbd..25dbc1d67 100644 --- a/src/ios/AppDelegate+notification.m +++ b/src/ios/AppDelegate+notification.m @@ -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 diff --git a/src/ios/PushPlugin.h b/src/ios/PushPlugin.h index 0945d5148..c43baa83b 100644 --- a/src/ios/PushPlugin.h +++ b/src/ios/PushPlugin.h @@ -38,6 +38,7 @@ NSString *notificationCallbackId; NSString *callback; BOOL clearBadge; + BOOL forceShow; NSMutableDictionary *handlerObj; void (^completionHandler)(UIBackgroundFetchResult); @@ -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; diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 0f5dac851..4f550ab92 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -44,6 +44,7 @@ @implementation PushPlugin : CDVPlugin @synthesize notificationCallbackId; @synthesize callback; @synthesize clearBadge; +@synthesize forceShow; @synthesize handlerObj; @synthesize usesFCM; @@ -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]) { @@ -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");