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
usingNSUserDefaults
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 thisNSTimer
’s firing method and just run it once at launch. Just be sure to update theNSDate
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.
精彩评论