我想要的是,我将当地通知设置为早上7点,并立即点火,通知会持续发出,直到用户不对通知执行任何操作或打开应用程序。
以下是第一次发送通知的代码
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)")
}
}
请建议连续发送本地通知。
谢谢
在您的日期组件中添加秒数
let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute], from: now)
通过递增秒来设置循环中每秒所需的通知数量。在iOS中,最大值为64。
点击通知时会关闭所有通知并重置以供下次使用。