views:

113

answers:

3

I want to check a file on the server only once each day (NSURL). And, no matter if I fetch the file or not, I do not run the function (to check for the file) again that day.

This would SEEM easy... but I forsee issues. Say I had created a directory under the mainBundle: "/Library/runOnceEachDay/". Perhaps I could write to /Library/runOnceEachDay/20100601 knowing that file would only exist if I already ran the function. If it does not exist, run the function and after the function is successful write a zero length file with the date as the filename. Then check before running that function for "mainBundle/Library/runOnceEachDay/YYYYMMDD" whereas YYYYMMDD is today's date. If that file exists, do not run.

I could run a housecleaning routine to clean that directory once/week or something. Any better ideas?

Thanks!

+4  A: 

The logic is good. You could either do it with files as you say and "Documents" folder is a good location for such files, or you could just have a NSUserDefaults key with the date when you last phoned home.

Jaanus
Isn't Documents BAD as it would be open to viewing by users with the new "drop box" permissions of iTunes -- but thx for responding so quickly.
Jann
+1 NSUserDefaults FTW!
Ukko
A: 

Wait, you can have iPhone apps running without the user opening them, once a day or once an hour? How?

Magarshak
No, not with current OS.
progrmr
The assumption by the OP would be that a user runs them manually at least once a day. Or doesn't care if a check home occurs only on days when they do.Even in 4.0, you couldn't execute arbitrary code via a scheduled local notification. Those only affect what push notifications do: play sounds, update badges, pop up alert views.
Joost Schuur
+2  A: 

When you start the app, get the previous phone home date/time (NSDate) from NSUserDefaults. (It won't be there the first time). This SO question (option 1) demonstrates how.

If more than 24 hours (or 7 days or whatever) has elapsed since that previous date/time (or you didn't find it there) then phone home and save the current date/time in NSUserDefaults for next startup.

progrmr