【发布时间】:2017-07-21 05:42:35
【问题描述】:
我想要什么,我将本地通知设置为上午 7:00,当它立即触发时,通知会不断发出,直到用户不对通知执行任何操作或打开应用程序。
下面是第一次发送通知的代码
let alarmNotification: UNMutableNotificationContent = UNMutableNotificationContent()
alarmNotification.title = "Demo"
alarmNotification.body = "Test"
alarmNotification.categoryIdentifier = "myDemoCategory"
let now = Date()
let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute], from: now)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let request = UNNotificationRequest(identifier: "TestNotification\(now)", content: alarmNotification, trigger: trigger)
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
请建议持续发送本地通知。
谢谢
【问题讨论】:
标签: ios swift swift3 localnotification unusernotificationcenter