diff --git a/src/messaging/messaging.d.ts b/src/messaging/messaging.d.ts index ed8bacf4..7c68beac 100644 --- a/src/messaging/messaging.d.ts +++ b/src/messaging/messaging.d.ts @@ -55,6 +55,7 @@ export interface IosInteractiveNotificationAction { submitLabel?: string; placeholder?: string; options?: IosInteractiveNotificationActionOptions; + category?: string; } export interface IosInteractiveNotificationCategory { diff --git a/src/messaging/messaging.ios.ts b/src/messaging/messaging.ios.ts index 05bf3ade..765f357a 100755 --- a/src/messaging/messaging.ios.ts +++ b/src/messaging/messaging.ios.ts @@ -196,36 +196,38 @@ export function addBackgroundRemoteNotificationHandler(appDelegate) { } export function registerForInteractivePush(model?: PushNotificationModel): void { - let nativeActions: Array = []; + let nativeCategories: Array = []; + + model.iosSettings.interactiveSettings.categories.forEach(category => { + let nativeActions: Array = []; - model.iosSettings.interactiveSettings.actions.forEach(((action: IosInteractiveNotificationAction) => { - let notificationActionOptions: UNNotificationActionOptions = action.options ? action.options.valueOf() : UNNotificationActionOptionNone; - let actionType: IosInteractiveNotificationType = action.type || "button"; - let nativeAction: UNNotificationAction; + model.iosSettings.interactiveSettings.actions.forEach(((action: IosInteractiveNotificationAction) => { + let notificationActionOptions: UNNotificationActionOptions = action.options ? action.options.valueOf() : UNNotificationActionOptionNone; + let actionType: IosInteractiveNotificationType = action.type || "button"; + let nativeAction: UNNotificationAction; - if (actionType === "input") { - nativeAction = UNTextInputNotificationAction.actionWithIdentifierTitleOptionsTextInputButtonTitleTextInputPlaceholder( + if (actionType === "input") { + nativeAction = UNTextInputNotificationAction.actionWithIdentifierTitleOptionsTextInputButtonTitleTextInputPlaceholder( action.identifier, action.title, notificationActionOptions, action.submitLabel || "Submit", action.placeholder); - } else if (actionType === "button") { - nativeAction = UNNotificationAction.actionWithIdentifierTitleOptions( + } else if (actionType === "button") { + nativeAction = UNNotificationAction.actionWithIdentifierTitleOptions( action.identifier, action.title, notificationActionOptions); - } else { - console.log("Unsupported action type: " + action.type); - } - - nativeActions.push(nativeAction); - })); + } else { + console.log("Unsupported action type: " + action.type); + } - let actions: NSArray = >NSArray.arrayWithArray(nativeActions); - let nativeCategories: Array = []; + if (action.category && action.category === category.identifier || !action.category) { + nativeActions.push(nativeAction); + } + })); - model.iosSettings.interactiveSettings.categories.forEach(category => { + let actions: NSArray = >NSArray.arrayWithArray(nativeActions); let nativeCategory = UNNotificationCategory.categoryWithIdentifierActionsIntentIdentifiersOptions(category.identifier, actions, null, null); nativeCategories.push(nativeCategory); @@ -531,9 +533,9 @@ class FirebaseNotificationDelegateObserverImpl implements DelegateObserver { } if (_showNotificationsWhenInForeground || // Default value, in case we always want to show when in foreground. - userInfoJSON["gcm.notification.showWhenInForeground"] === "true" || // This is for FCM, ... - userInfoJSON["showWhenInForeground"] === true || // ...this is for non-FCM... - (userInfoJSON.aps && userInfoJSON.aps.showWhenInForeground === true) // ...and this as well (so users can choose where to put it). + userInfoJSON["gcm.notification.showWhenInForeground"] === "true" || // This is for FCM, ... + userInfoJSON["showWhenInForeground"] === true || // ...this is for non-FCM... + (userInfoJSON.aps && userInfoJSON.aps.showWhenInForeground === true) // ...and this as well (so users can choose where to put it). ) { completionHandler(UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Badge); } else {