如何将操作按钮添加到有效负载 onesignal json apns 文件

问题描述 投票:0回答:2

我尝试在通知中添加操作按钮信号react-native ios。所以我使用apns文件在模拟器中进行测试,通知随拖动文件一起出现,但即使我长按也不会出现操作按钮任何人都可以给我正确的aps格式化json并寻求帮助 这是我用于测试的有效负载 apns 文件:

{
    "Simulator Target Bundle": "******",
    "aps": {
        "alert": {
            "title": "Push Notification",
            "subtitle": "Test Push Notifications",
            "body": "Testing Push Notifications on iOS Simulator",
            "actionButtons":[
                       {
                       "id":"test",
                       "text":"test"
                        }
                           ]
             
        }
    },
    "custom": {
        "i": "notificationId as UUID",
        "a": {"deeplinkKey": "{\"deeplinkDetailKey\":\"deeplinkDetailValue\"}", "launchURL": "example://collection/myCollectionId/type/1"}
    }
}
ios react-native notifications onesignal payload
2个回答
0
投票
  • OneSignal 不支持 iOS 推送通知中的操作按钮。您可以通过在有效负载中包含类别来实现类似的效果。这是修改有效负载以添加类别的示例。

    {
     "Simulator Target Bundle": "******",
     "aps": {
         "alert": {
             "title": "Push Notification",
             "subtitle": "Test Push Notifications",
             "body": "Testing Push Notifications on iOS Simulator"
         },
         "category": "testCategory"
     },
     "custom": {
         "i": "notificationId as UUID",
         "a": {"deeplinkKey": "{\"deeplinkDetailKey\":\"deeplinkDetailValue\"}", "launchURL": "example://collection/myCollectionId/type/1"}
     }
    }
    
  • 在应用程序的代码中,您可以在 UNUserNotificationCenterDelegate 的 didReceiveRemoteNotification 方法中处理类别

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
     if response.notification.request.content.categoryIdentifier == "testCategory" {
         // Handle the category action here
     }
     completionHandler()
    }
    
  • 用户通知 从服务器将面向用户的通知推送到用户的设备,或从您的应用程序在本地生成通知:https://developer.apple.com/documentation/usernotifications


0
投票

我通过将这些包含类别名称和操作按钮的行添加到 AppDelegate.m 文件中解决了我的问题

// Define notification actions (the buttons)
  UNNotificationAction *acceptAction = [UNNotificationAction actionWithIdentifier:@"accept" title:@"Accept" options:UNNotificationActionOptionForeground];
  UNNotificationAction *declineAction = [UNNotificationAction actionWithIdentifier:@"ignore" title:@"Decline" options:UNNotificationActionOptionDestructive];
  // Define the notification category with the actions
  UNNotificationCategory *inviteCategory = [UNNotificationCategory categoryWithIdentifier:@"myapp_action" actions:@[acceptAction, declineAction]
                                  intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
© www.soinside.com 2019 - 2024. All rights reserved.