我正在按照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)
}
从本地通知中,我在拉动时有两个按钮。
但是没有出现在远程推送中。
答案 0 :(得分:1)
请按照以下说明更改通知有效负载JSON
{"to": "d8xNDuQIua8:APA91bF15SABFUBNDEYb2JJ4_LGlDZ94G3TMryWIo0SFKE1xyr9VThS6Ce-NofxXtIAw_yMr5jFwUcEzk-JxqpqkJ5OiOYzftcukyef1VcX4a7I25BagAytp48GVt1VJueY49K2cAKcA",
"notification": {
"text": "YOUR_PUSH_TEXT",
"click_action":"INVITE_CATEGORY"
}
}