我试图为这个问题找到一个确切的答案:“设备重启后我的预定通知会发生什么?”。
我已经使用UNUserNotificationCenter
来安排所有通知,它们将根据安排的时间在每天重复触发。
这是我编写的代码片段,它在设备开启时工作。
func scheduleNotification() {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "This is the title"
content.body = "The is the body"
content.categoryIdentifier = "identifier"
content.userInfo = ["info":"B"]
content.sound = UNNotificationSound.default
var dateComponents = DateComponents()
dateComponents.hour = 0
dateComponents.minute = 29
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.removeAllPendingNotificationRequests()
center.add(request)
}