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

Allow associating different quick actions per notification categories. #1644

Open
wants to merge 1 commit 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 src/messaging/messaging.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface IosInteractiveNotificationAction {
submitLabel?: string;
placeholder?: string;
options?: IosInteractiveNotificationActionOptions;
category?: string;
}

export interface IosInteractiveNotificationCategory {
Expand Down
44 changes: 23 additions & 21 deletions src/messaging/messaging.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,36 +196,38 @@ export function addBackgroundRemoteNotificationHandler(appDelegate) {
}

export function registerForInteractivePush(model?: PushNotificationModel): void {
let nativeActions: Array<UNNotificationAction> = [];
let nativeCategories: Array<UNNotificationCategory> = [];

model.iosSettings.interactiveSettings.categories.forEach(category => {
let nativeActions: Array<UNNotificationAction> = [];

model.iosSettings.interactiveSettings.actions.forEach(((action: IosInteractiveNotificationAction) => {
let notificationActionOptions: UNNotificationActionOptions = action.options ? <UNNotificationActionOptions>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 ? <UNNotificationActionOptions>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<UNNotificationAction> = <NSArray<UNNotificationAction>>NSArray.arrayWithArray(<any>nativeActions);
let nativeCategories: Array<UNNotificationCategory> = [];
if (action.category && action.category === category.identifier || !action.category) {
nativeActions.push(nativeAction);
}
}));

model.iosSettings.interactiveSettings.categories.forEach(category => {
let actions: NSArray<UNNotificationAction> = <NSArray<UNNotificationAction>>NSArray.arrayWithArray(<any>nativeActions);
let nativeCategory = UNNotificationCategory.categoryWithIdentifierActionsIntentIdentifiersOptions(category.identifier, actions, null, null);

nativeCategories.push(nativeCategory);
Expand Down Expand Up @@ -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 {
Expand Down