【问题标题】:What will happen to Scheduled notifications after the device Reboots?设备重启后计划通知会发生什么情况?
【发布时间】:2021-06-29 15:04:22
【问题描述】:

我试图为这个问题找到一个确切的答案:“设备重启后我的预定通知会发生什么?”。

我已使用UNUserNotificationCenter 安排所有通知,它们将根据安排的时间在每天重复触发。

这是我编写的代码 sn-p,它可以在设备开启时工作。

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)
}

【问题讨论】:

    标签: ios swift uilocalnotification reboot unnotificationrequest


    【解决方案1】:

    简而言之,它应该保留,虽然我找不到苹果官方文档,但它对我有用。计时器应该在重新启动后仍然存在。只要在相关时间到来时设备处于开启状态并且应用程序仍在安装中,就会触发通知。当然需要发送通知的权限。

    之前有人问过这个问题,但没有答案 - UNUserNotificationCenter notifications after device reboot

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多