我一直在线搜索,看看您安排的通知是否会在设备重新启动后被删除。我发现意见不一,所以我开始测试了。这就是我注意到的:
下面是我用来进行日程安排的一段代码:
let notificationContent = UNMutableNotificationContent()
notificationContent.body = "This is a notification"
notificationContent.categoryIdentifier = NotificationContentProvider.snoozeCategoryIdentifier
let unitFlags = [.hour, .minute, .second, .day, .month, .year] as [Calendar.Component]
let components = Calendar.current.dateComponents(Set(unitFlags), from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)
let request = UNNotificationRequest(identifier: "\(Int.random())", content: notificationContent, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
if let theError = error {
print(theError.localizedDescription)
}
})