OStack程序员社区-中国程序员成长平台

标题: iOS 通知动态操作类别 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:45
标题: iOS 通知动态操作类别

我需要通过有效负载显示推送通知的动态操作。像这样:

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

它的好习惯是什么?到目前为止有可能吗?

目前我正在对类别使用静态配置,并且效果很好:

        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));

但不处理任务



Best Answer-推荐答案


到目前为止,我认为您无法通过有效负载显示推送通知的动态操作。iOS 系统不支持您这样做。

在 iOS 文档的 UNNotificationAction 部分,它写道:

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

可以引用:

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

关于iOS 通知动态操作类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53048306/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4