iOS Notification Dynamic Action Categories

Viewed 920

I need to show dynamic actions for push notifications by payload . something like this :

 {
Platform": "apns",
    "Title":"Booking from API",
    "Content": "Hello there",
    "Category": "confirmBooking",
    "Actions":[
        {
            "ButtonText": "Confirm",
            "ActionName": "confirmBooking"
        },
        {
            "ButtonText": "Decline",
            "ActionName": "declineBooking"
        },
    ]
}

what is the good practice of it ? is it possible so far?

for now I'm using static configuration for categories and it works fine:

        var confirm_action = UNNotificationAction.FromIdentifier("confirm", "Confirm", UNNotificationActionOptions.None);
        var decline_action = UNNotificationAction.FromIdentifier("decline", "Decline", UNNotificationActionOptions.None);

        // Create category
        var categoryID = "bookingConfirm";
        var actions = new UNNotificationAction[] { confirm_action, decline_action };
        var intentIDs = new string[] { };
        var categoryOptions = new UNNotificationCategoryOptions[] { };
        var category = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);


        var categories = new UNNotificationCategory[] { category };
        UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet<UNNotificationCategory>(categories));

but doesn't handle the task

1 Answers

I don't think you can show dynamic actions for push notifications by payload so far.The iOS system does not support you to do that.

In the UNNotificationAction part of iOS documentation,it writes:

Because your app must handle all actions, you must declare the actions that your app supports at launch time.

You can refer to:

https://developer.apple.com/documentation/usernotifications/unnotificationaction https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types

Related