开发者

Auto-update iPhone content

I am developing an enterprise app which has a lot of dynamic content. Is there a way to have the app auto update the cont开发者_开发技巧ent(new stories, download new videos, etc) at 3am every Sunday.

Is this possible?


While it’s not possible to do this when the app isn’t running, you can do it fairly easily at launch or while running (if it’s going to be running at 3 AM). Here’s what I’d do:

  • Store an NSDate using NSUserDefaults for the last time you updated.
  • At launch, if a 3 AM period has passed since that date, initiate a sync.
  • Also at launch, start an NSTimer with a long interval—5 minutes or so. At each firing, check if a 3 AM period has passed and if it has, initiate a sync. You could even roll the last bullet’s code into this NSTimer’s firing method and just run it once at launch. Just be sure to update the NSDate object each time.
  • In the application delegate, in the methods called from returning from the background, check the time and sync if necessary—or just start the NSTimer and have it fire immediately first.

That should cover all of the scenarios where you need to update the app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜