【发布时间】:2016-07-21 07:54:16
【问题描述】:
我目前在 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!)
}
}
【问题讨论】:
-
你添加 UNNotificationContentExtension 吗?
-
不确定
UNNotificationAction但在警报中您需要使用alert.addAction(ok)实际添加按钮,这不一样吗?
标签: swift notifications ios10 unusernotificationcenter