我一直在网上搜索,看看您安排的通知是否会在设备重新启动后被删除。我发现了不同的意见,所以我开始测试它。这是我注意到的:
- 我安排了 10 分钟后的通知,重新启动手机:没有任何反应
- 但是,昨天我安排了很多通知,其中一些是当天的。尽管从昨天开始我已经多次重启手机,但这些通知确实出现了。
下面是我用来进行调度的代码片段:
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)
}
})
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)