0

I have to setting a time to check for update data from server 2times a day, suppose 9AM and 9PM, but i don't know the way to do that.

Create a thread, run every-time and check time current time with setting,if they are equal,so do task? This way is good? I think that's bad performance.

madth3
  • 7,275
  • 12
  • 50
  • 74
The Bird
  • 397
  • 2
  • 8
  • 19
  • If you factor in the time difference between the current time and the target, it would not be a huge performance hit. I feel that there should be better ways to do it though. – Alex Gittemeier Jan 23 '13 at 08:26
  • there are some unique services which can run in the background on iOS, when your application is in sleep mode: _location services_, _audio services_, _VoIP_. every other threads will be suspended and no thread is running when your application is terminated by any reason. – holex Jan 23 '13 at 08:26

2 Answers2

2

maybe when your app is launching , you can get the current time(also can get the timeInterval of current time called timeInterval0) using [NSDate date] and if your current time < 9:00AM today , you can get the timeInterval of 9:00AM today called timeInterval1. and then you can get how many seconds between now and your target time , then use NSTimer to invocation your method ,the delay is the between seconds.

In your method , you can check the update , and you must also to calc the seconds from then between next 9:00 as above.

Guo Luchuan
  • 4,729
  • 25
  • 33
0

Use thread but instead of checking every sec, if it is equal. You could use NSNotification. When the time is the same, it will send a notification to get the data.

You can read this: iOS timed background processing

Can go through this tutorial as well: http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-local-notifications/

I have reading up as well. Something new for me as well. Best is NSLocalNotifications. Have a look at this: Reminder App

The documentation for Local Notifications: Local Notifications

Community
  • 1
  • 1
lakshmen
  • 28,346
  • 66
  • 178
  • 276