swift - 自定义操作按钮未显示用于远程通知

标签 swift push-notification remote-notifications

我正在关注 this生成通知的教程。如图所示,自定义按钮对于本地通知是可见的。但是当我对远程尝试相同时,它没有用。

这是我设置通知类别的代码:

func registerActions() {
    var notificationActionOk :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
    notificationActionOk.identifier = "ACCEPT_IDENTIFIER"
    notificationActionOk.title = "Ok"
    notificationActionOk.isDestructive = false
    notificationActionOk.isAuthenticationRequired = false
    notificationActionOk.activationMode = UIUserNotificationActivationMode.background

    var notificationActionCancel :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
    notificationActionCancel.identifier = "NOT_NOW_IDENTIFIER"
    notificationActionCancel.title = "Not Now"
    notificationActionCancel.isDestructive = true
    notificationActionCancel.isAuthenticationRequired = false
    notificationActionCancel.activationMode = UIUserNotificationActivationMode.background

    var notificationCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
    notificationCategory.identifier = "INVITE_CATEGORY"
    notificationCategory .setActions([notificationActionOk,notificationActionCancel], for: UIUserNotificationActionContext.default)
    notificationCategory .setActions([notificationActionOk,notificationActionCancel], for: UIUserNotificationActionContext.minimal)

    UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: UIUserNotificationType(rawValue: UIUserNotificationType.sound.rawValue | UIUserNotificationType.alert.rawValue |
        UIUserNotificationType.badge.rawValue), categories: NSSet(array:[notificationCategory]) as! Set<UIUserNotificationCategory>
    ))

//        fireLocalNotification()
}

这是我添加的相同类别的有效负载。

{"to": "cMGOnedo5M4:APA91bEQgj1Dt5IWsqgdq2QQmGBv-zAxH4qsWRApkeAA5fvxCZPKQACkok_sWC3v2mwT3SnFrK_08qgmy9bcac0PxSJkSWhJMKbWPnBzHWBnv2yKPY-FjSynLgGYTiK7bl5LejcaVQbr", 
"notification" : 
    {"body" : "   ","title": "You have received a message from jia ron","badge": "1" },
"data" : 
    {"OriginalFileName":null,"FilePath":"https:Chat//3458/","ChatID":3826,"From":3458,"To":3440,"Message":null,"SendDate":"2019-07-03T00:00:00","ServerDate":"","ModifyDate":"","SendType":"TEXT","IsDelete":false,"IsRead":false,"SendByMe":0,"Type":"OfflineChat","message":null,"UserID":"3458","DisplayName":"jia ron","MessageType":"TEXT","IsGroup":0,"GroupID":0,"FileName":null,"UnreadMessage":3},
"aps" :
  {"category" : "INVITE_CATEGORY"}
}

这是触发本地通知的代码。

func fireLocalNotification() {
    var localNotification:UILocalNotification = UILocalNotification()
    localNotification.alertAction = "Testing notifications on iOS8"
    localNotification.alertBody = "Woww it works!!"
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 30) as Date
    localNotification.category = "INVITE_CATEGORY";
    UIApplication.shared.scheduleLocalNotification(localNotification)
}

从本地通知中,我得到了两个按钮。

enter image description here

但是没有出现在远程推送上。

enter image description here

最佳答案

请按照以下更改您的通知负载 JSON

{"to": "d8xNDuQIua8:APA91bF15SABFUBNDEYb2JJ4_LGlDZ94G3TMryWIo0SFKE1xyr9VThS6Ce-NofxXtIAw_yMr5jFwUcEzk-JxqpqkJ5OiOYzftcukyef1VcX4a7I25BagAytp48GVt1VJueY49K2cAKcA",
     "notification": {
         "text": "YOUR_PUSH_TEXT",
         "click_action":"INVITE_CATEGORY"
     }
}

关于swift - 自定义操作按钮未显示用于远程通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57440016/

相关文章:

iphone - 推送通知进入时的警报序列

ios决定是否在客户端代码的某些条件下静音我的远程通知,而不是设置内容可用

swift - 从 Firebase 读取数据到 swift3 EXC_BAD_INSTRUCTION

ios - 使用 coredata 快速处理临时值的最佳方法

ios - Interface Builder 错误地调整导航项

swift - 在原生 iOS/swift 的 Google Maps SDK 中获取位置标记

ios - 验证返回码 : 20 (unable to get local issuer certificate) while creating push notification P EM file

javascript - 让 HTML5 推送通知适用于所有网络浏览器和移动浏览器?

ios - 是否可以在后台模式下收到远程推送通知时多次振动?

ios - 如何根据远程通知类型将用户重定向到各种屏幕