【发布时间】:2019-09-12 07:54:17
【问题描述】:
我在下面有这段代码来测试每小时本地通知的工作方式。但我什么也没得到。
另外,有没有办法在不同的时间发送不同的本地通知消息?我只是在 viewDidLoad() 中调用 LocalNotificationHour()
我刚开始学习 swift,所以我很抱歉。
--
@objc func LocalNotificationHour() {
let user = UNUserNotificationCenter.current()
user.requestAuthorization(options: [.alert,.sound]) { (granted, error) in}
let content = UNMutableNotificationContent()
content.title = "Local Notification"
content.body = "This is a test."
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
dateComponents.hour = 1
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let uuid = UUID().uuidString
let request = UNNotificationRequest(identifier: uuid, content: content, trigger: trigger)
user.add(request) { (error) in print("Error")}
}
【问题讨论】:
标签: ios swift notifications local localnotification