设置推送通知操作按钮

Set push notification Action Buttons

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 个带有按钮的推送通知的任何建议或示例。

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

中调用 notification.category = 'shopping';

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

你是哪个服务器端运行?

此外,这有望在您的应用委托中吗?我把这整个东西变成了一个函数,我称之为 setActions() 然后我在 DidFinishLaunchingWithOptions

中调用了 setActions()

此代码位于您基地的什么位置?