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

Custom action buttons didn't show for remote notification

我正在学习 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)
}

根据本地通知,我有两个拉动按钮。

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

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

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