6

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. :)

ishaqbhojani
  • 302
  • 1
  • 12

1 Answers1

0

Please refer to this stackoverflow post about an API you can use to receive callbacks at times relative to sunrise/sunset. That answer explains how to use the API as well.

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.

MRC
  • 56
  • 4
  • 1
    Thanks for your answer, I've already found the solution for android using background services. This API works well but it's not available in iOS. Any Alternate solution for iOS? – ishaqbhojani Sep 05 '17 at 07:41
  • Starting a background service for your app will not work your your app anymore due to [background-restrictions](https://developer.android.com/about/versions/oreo/background.html) from [Android Oreo](https://developer.android.com/about/versions/oreo/android-8.0.html) onwards. Perhaps using this or other API will save you time to migrate later on. – MRC Sep 05 '17 at 16:43
  • 1
    Ok, I'll use this API for android, but this is not available for iOS. What should i do for iOS ? – ishaqbhojani Sep 06 '17 at 05:11