设置推送通知操作按钮

时间:2017-03-01 13:29:52

标签: ios iphone push-notification apple-push-notifications ios10

UNNotificationAction *shopAction = [UNNotificationAction actionWithIdentifier:@"ShopNow"

                                                                        title:@"Shop Now ️" options:UNNotificationActionOptionNone];

UNNotificationAction *dismissAction = [UNNotificationAction actionWithIdentifier:@"Dismiss"

                                                                           title:@"Dismiss" options:UNNotificationActionOptionDestructive];



UNNotificationCategory *shopCategory = [UNNotificationCategory categoryWithIdentifier:@"Shopping"

                                                                              actions:@[shopAction,dismissAction] intentIdentifiers:@[]

                                                                              options:UNNotificationCategoryOptionNone];

NSSet *categories = [NSSet setWithObjects:shopCategory, nil];

[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories];

我尝试了上面的代码,但在我的推送通知中没有显示按钮。通过按钮提供iOS 10推送通知的任何建议或示例。

1 个答案:

答案 0 :(得分:1)

您需要在JSON中调用category: 'shopping',或在NODE .js中调用notification.category = 'shopping';

对于JSON,您可能还需要在类别之前加入"mutable-content": 1

您正在运行哪个服务器端?

此外,这是您的应用程序代表希望?我把这整件事变成了一个名为setActions()的函数,然后我在setActions()内调用了DidFinishLaunchingWithOptions

此代码位于您的基地?