无法查看iOS 10本地通知的操作按钮

nik*_*iks 1 notifications swift ios10 unusernotificationcenter

我在iOS 10上按时间间隔通知查看操作按钮时遇到问题.我创建了两个UNNotificationAction对象'OK'和'Cancel'作为通知类别添加.

我在没有任何操作按钮的模拟器上收到通知.以下是我的代码.

let ok = UNNotificationAction(identifier: "OKIdentifier",
                                      title: "OK", options: [])

let cancel = UNNotificationAction(identifier: "CancelIdentifier",
                                  title: "Cancel",
                                  options: [])

let category = UNNotificationCategory(identifier: "message",
                                      actions: [ok, cancel],
                                      minimalActions: [ok, cancel],
                                      intentIdentifiers: [],
                                      options: [])

UNUserNotificationCenter.current().setNotificationCategories([category!])

let content = UNMutableNotificationContent()
content.title = contentTitle
content.subtitle = contentSubtitle
content.body = contentBody

let model: TimeIntervalNotificationModel = notificationsModel as!  TimeIntervalNotificationModel

trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: model.timeInterval!, repeats: notificationsModel.repeats) as UNTimeIntervalNotificationTrigger

let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: trigger)

UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request){(error) in
                if (error != nil){
                    //handle here
         print("Error: Adding notification failed:\(error?.description)")

         self.delegate?.didFailToAddNotification(error: error!)
                }
            }
Run Code Online (Sandbox Code Playgroud)

nik*_*iks 10

解决了这个问题.忘记设置通知内容的类别标识符属性.

content.categoryIdentifier = "message"
Run Code Online (Sandbox Code Playgroud)

定义:

应用程序定义的类别对象的标识符指定类别标识符以创建可操作的通知.标识符必须属于您之前在应用程序中注册的UNNotificationCategory对象.当通知传递给用户时,系统会根据需要将该类别对象中定义的操作添加到通知界面.