在 iOS,如何为没有类别的推送通知指定自定义操作?

On iOS, how do you specify a custom action for a push notification without a category?

我们目前使用的推送服务尚不允许自定义类别。话虽如此,我们所有的推送都需要相同的 "Reply" 操作。是否可以在推送通知的 aps 负载中没有 category 属性 的情况下完成此操作?

Reference

谢谢!

通知需要一个类别才能具有自定义操作。类别是 OS 用于查找与您的通知关联的自定义操作的类别。 Apple 文档指出:

When your push server wants to send a notification to a user, it can add a category key with an appropriate value to the notification’s payload. When iOS sees a push notification with a category key, it looks up the categories that were registered by the app. If iOS finds a match, it displays the corresponding actions with the notification.

也适用于本地通知

In the case of a local notification, you create the notification as usual, then set the category of the actions to be presented, and finally, schedule the notification as usual

      UILocalNotification *notification = [[UILocalNotification alloc] init];
      notification.category = @"INVITE_CATEGORY";
      [[UIApplication sharedApplication] scheduleLocalNotification:notification]