简体   繁体   English

在iOS中的不同时间每天实现多个本地通知的逻辑

[英]Implement a logic for multiple local notifications daily on different time in iOS

Actually, I'm developing an App that triggers local notifications on sunrise and sunset time (which differs daily, so can not use alarm). 实际上,我正在开发一个应用程序,可以在日出和日落时间触发本地通知(每天都有所不同,所以不能使用闹钟)。 Additionally I need this functionality offline. 另外,我需要脱机使用此功能。

I've already tried: 我已经尝试过了:

  • Register whole years notifications at once but it does not work because of notifications limit restrictions 立即注册全年通知,但由于通知限制限制,它不起作用
  • Register next notification on trigger event of current notification but this logic fails when a notification does not trigger when device is switched off. 在当前通知的触发事件上注册下一个通知,但是当设备关闭时没有触发通知时,此逻辑会失败。

Any help would be appreciated. 任何帮助,将不胜感激。 :) :)

Please refer to this stackoverflow post about an API you can use to receive callbacks at times relative to sunrise/sunset. 请参阅此stackoverflow帖子,了解可用于在相对于日出/日落时间接收回调的API。 That answer explains how to use the API as well. 该答案解释了如何使用API​​。

This question differs slightly from that other one, therefore I'm not marking duplicate. 这个问题与其他问题略有不同,因此我没有标记重复。 The thing to add that is specific to this question is that you will not need to pre-compute the sunrise/set for long periods and register a bunch of alarms. 要添加的特定于此问题的是,您不需要长时间预先计算日出/设置并注册一堆警报。 Aside of being inelegant the precompute solution will not work on mobile because sunrise/set depends on device-location, and you cannot know where the device is located for long periods in future. 除了不优雅之外,预计算解决方案将无法在移动设备上运行,因为日出/设置取决于设备位置,并且您将来无法长时间知道设备的位置。

With the suggested Awareness API , specifically TimeFence.aroundTimeInstant() you will automatically get a callback at some specified offset from sunrise/set and you can unregister from the API at any time to stop receiving them. 使用建议的Awareness API ,特别是TimeFence.aroundTimeInstant(),您将在日出/设置的某个指定偏移处自动获得回调,您可以随时从API取消注册以停止接收它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM