0

I'm creating an app that needs to fire local notifications for sunrise and sunset on a daily basis.

  • Sunrise and sunset times changes every day.
  • I want the registering of the local notifications to take place even if the user didn't open the app (i.e. a background task). So the user installs the app, sets his location (since sunrise and susnet calculations are location based) and then he knows he'll get notifications for sunrise and set every day without needing to open the app or being connected to the internet.
  • Ideally I need a background task for registering local notifications over a given period which runs at least once every period. "e.g. registers local notifications for the next week, which in that case I need it to run at least once a week".
  • None of the current background modes fit my case, I tried a background fetch, but since there're no data downloaded iOS stopped running my background task after a couple of days
  • I know I can use push notifications, but I don't want to unless it's my last option, cause I want the notification to take place even if the phone was not connected to the internet.

So how do you think I can tackle this? Is there something I'm missing?

Ahmed
  • 1

1 Answers1

0

Get Location for every ’n’ minutes in background. By Using beginBackgroundTaskWithExpirationHandler and NSTimer .it keeps app live in background. So, You can schedule a localnotification in background. For getting location update in background Refer the link How do I get a background location update every n minutes in my iOS application?

(From iOS7 finite-length background task time reduced to 180 seconds. so you must fetch location within next 180 seconds.) If user force quit the app. the app destroyed all the task . Use Significant location change or region monitoring to restart the Background task and get location for every ’n’ minutes.

Community
  • 1
  • 1
Prabha
  • 31
  • 9
  • I thought that's not the case anymore. I think iOS will suspend the NSTimer once you reach the threshold. and the only way to fire the app in the background is through a background execution with one of the background modes. – Ahmed Oct 27 '15 at 13:02
  • If you get the location with in 180 seconds. the app life extends to another 180 seconds. you get location for every 180 sec. you can check the background remaining time by NSLog(@"backgroundTimeRemaining: %.0f", [[UIApplication sharedApplication] backgroundTimeRemaining]); – Prabha Oct 27 '15 at 14:20