-1

I want background service which run after every 10 minutes to fetch data from url and update it in database.

I have searched a lot. it give me examples which run continuously for 3 minutes and then stop. or examples of pull and refresh data.

but I want service which run in background without user interaction and it should be run after every 10 minutes.

Is there any tutorial or example for this? What is the effective way to achieve this?

Learner
  • 1
  • 1
  • Have you tried with NSTimer adding to NSRunloop by setting up time interval to 10 mins & repeat YES ? – Mayur Prajapati Feb 10 '15 at 06:25
  • No. but is it effective way to do this? and is there any other way? – Learner Feb 10 '15 at 06:29
  • there may be multiple ways but as you required repeating than this is the best one i suggest – Mayur Prajapati Feb 10 '15 at 06:30
  • will it work even if app is closed ? – Learner Feb 10 '15 at 06:40
  • no it will not work. – Mayur Prajapati Feb 10 '15 at 06:41
  • I need it without user interaction. Even if app is close. Background service should be run after every 10minutes. – Learner Feb 10 '15 at 06:53
  • 1
    You can use Apple Background fetching new in iOS7 but this not ensures you when updates data. It will update based on user usage of your app. Other option if you have only a few users is via silent push notifications to force the app to fetch data – Christian Feb 10 '15 at 07:24
  • There is no clean, guaranteed way to achieve this in iOS without using a private API. This is by design; Apple doesn't want apps to be able to fire up behind users' backs and start hogging CPU resources / draining batteries. – davidf2281 Feb 10 '15 at 10:49
  • I don't see why people are flagging this as opinion-based: it is a technical question with specific technical answers. There doesn't seem to be an existing question on SO with a full answer - http://stackoverflow.com/questions/27877335/ios-background-fetch comes close. @Christian you should put your comment in as an answer. – Bryan Feb 10 '15 at 14:09

2 Answers2

0

Integrate Parse link into your project. It will give specific time to run your background process. By using this Parse we can create push notifications and also gives crash reporting.

vishnu
  • 715
  • 9
  • 20
0

There is a tricky way you can have a try:

  1. Schedule a NSTimer.
  2. Switch on/off the locationManager alternately every... for example, 10 seconds, 20 seconds, you want.

    [_locationManager startUpdatingLocation] and [_locationManager stopUpdatingLocation]

  3. Set the app info.plist: at the "Required background modes", add "App registers for location updates"

hopefully help!!!

ZanderHo
  • 26
  • 3