我们已经使用通知扩展服务实现了可操作通知。我们会收到推送通知,它会显示通知标题,正文,操作按钮的正确内容。我们定义了3个类别,分别是 onebtn , twobtn , threebtn 和每个类别的所有唯一操作。
因此,所有内容对于一个通知都可以正常工作,但是当我们在通知托盘中收到多个通知时,最近通知操作按钮的文本替换为所有其他通知操作按钮的文本。例如我收到了有关 threebtn 类别的通知,它将显示三个带有三个不同文本的按钮,分别为 Now,Late和Cancel (这三个按钮名称将成为付费的一部分)收到推送通知)。现在,我又收到了一个关于twobtn类别的通知,其中包含按钮名称答复并标记为已读,并显示了该通知。
现在的问题是,它将类别twobtn的按钮名称覆盖到为threebtn通知收到的通知中。这意味着当我拖动并打开类别Threebtn的通知时,其按钮名称将为答复,标记为已付款并取消 (分配操作时定义的第三默认文本)。因此,每个通知的名称都将为“答复并标记为已付费”。
尝试过的解决方案:
一个星期以来,我一直在解决此问题,但找不到任何合适的解决方案。请给我一些提示,以便我解决。
谢谢。
class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
let (pushNotificationBean, _) = saveNotificationAppGroupDefault(saveNotificationUserInfo: request.content.userInfo)
registerNotificationCategory(pushNotificationBean: pushNotificationBean)
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
}
// MARK: - Register Notificaion Categories and Actions
func registerNotificationCategory(pushNotificationBean: PushNotificationBean) {
// Define Actions
if #available(iOS 10.0, *) {
// Define Action Yes
var singleBtnAction : UNNotificationAction
var trippleBtnYesAction : UNNotificationAction
var trippleBtnNoAction : UNNotificationAction
var trippleBtnPartialAction : UNNotificationAction
var doubleBtnYesAction : UNNotificationAction
var doubleBtNoAction : UNNotificationAction
// Positve Button Text
if let okActionText = pushNotificationBean.actionPositiveText, okActionText.count > 0{
// Single Button Action
singleBtnAction = UNNotificationAction(identifier: self.OkAction,
title: okActionText,
options: .foreground)
// Double Button Action
doubleBtnYesAction = UNNotificationAction(identifier: self.YesAction,
title: okActionText,
options: .foreground)
// Tripple Button Action
trippleBtnYesAction = UNNotificationAction(identifier: self.YesAction,
title: okActionText,
options: .foreground)
}else{
// Single Button Action
singleBtnAction = UNNotificationAction(identifier: self.OkAction,
title: self.OkAction,
options: .foreground)
// Double Button Action
doubleBtnYesAction = UNNotificationAction(identifier: self.YesAction,
title: self.YesAction,
options: .foreground)
// Tripple Button Action
trippleBtnYesAction = UNNotificationAction(identifier: self.YesAction,
title: self.YesAction,
options: .foreground)
}
// Negative Action Text
if let noActionText = pushNotificationBean.actionNegativeText, noActionText.count > 0{
// Double Button Action
doubleBtNoAction = UNNotificationAction(identifier: self.NoAction,
title: noActionText,
options: .foreground)
// Tripple Button Action
trippleBtnNoAction = UNNotificationAction(identifier: self.NoAction,
title: noActionText,
options: .foreground)
} else{
// Double Button Action
doubleBtNoAction = UNNotificationAction(identifier: self.NoAction,
title: self.NoAction,
options: .foreground)
// Tripple Button Action
trippleBtnNoAction = UNNotificationAction(identifier: self.NoAction,
title: self.NoAction,
options: .foreground)
}
// Partial Action Text
if let trippleBtnPartialActionText = pushNotificationBean.actionNeutralText, trippleBtnPartialActionText.count > 0{
// Tripple Button Action
trippleBtnPartialAction = UNNotificationAction(identifier: self.PartialAction,
title: trippleBtnPartialActionText,
options: .foreground)
}else{
// Tripple Button Action
trippleBtnPartialAction = UNNotificationAction(identifier: self.PartialAction,
title: self.PartialAction,
options: .foreground)
}
// Define Single Category
let singleButtonCategory = UNNotificationCategory(identifier: self.SingleButton,
actions: [singleBtnAction],
intentIdentifiers: [self.OkAction],
options: [])
// Define Double Category
let doubleButtonCategory = UNNotificationCategory(identifier: self.DoubleButton,
actions: [doubleBtnYesAction,doubleBtNoAction],
intentIdentifiers: [self.YesAction,self.NoAction],
options: [])
// Define Tripple Category
let tripleButtonCategory = UNNotificationCategory(identifier: self.TripleButton,
actions: [trippleBtnYesAction,trippleBtnNoAction,trippleBtnPartialAction],
intentIdentifiers: [self.YesAction,self.NoAction,self.PartialAction],
options: [])
UNUserNotificationCenter.current().setNotificationCategories([singleButtonCategory,doubleButtonCategory,tripleButtonCategory])
}
}
}