【问题标题】:LocalNotification on device reboot设备重启时的本地通知
【发布时间】:2014-11-30 20:55:36
【问题描述】:

我有一个 iOS 应用程序,它每 4 小时左右触发一次本地通知。这似乎按预期成功运行。不过,我担心的是如果用户重新启动设备该怎么办。任何现有的本地通知是否仍然存在?以下是我触发本地通知的方式:

    var localNotification:UILocalNotification = UILocalNotification()
    localNotification.alertAction = "report_alarm"
    localNotification.alertBody = "Please file report"
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 4 * 60 * 60)
    localNotification.soundName = UILocalNotificationDefaultSoundName
    UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

如果用户在 4 小时内重启设备,还会触发本地通知吗?如果没有,有什么方法可以在设备完成重启时通知我的应用程序并且我可以设置必要的本地通知?感谢您的帮助!

【问题讨论】:

标签: ios swift uilocalnotification


【解决方案1】:

重启后通知将消失。 (这很容易测试,顺便说一句。)

您可以使用UIApplication API 在应用启动时检查活动通知:

UIApplication.sharedApplication().scheduledLocalNotifications

如果需要,您可以使用通知的userInfo 字典属性来识别它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 2023-04-02
    相关资源
    最近更新 更多