我需要通过有效负载显示用于推送通知的动态操作。像这样的东西:
{
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));
但不处理任务
答案 0 :(得分:0)
到目前为止,我认为您无法针对有效负载显示推送通知的动态操作。iOS系统不支持您这样做。
在iOS文档的UNNotificationAction
部分中,它写道:
由于您的应用必须处理所有操作,因此必须声明这些操作 您的应用支持
at launch time
。
您可以参考:
https://developer.apple.com/documentation/usernotifications/unnotificationaction https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types