Quote:
Originally Posted by kamaleshj
Hi
I'm developing an app that will present a message to the iPhone/iPad user each day. One message will be presented from this database on each new day of the calendar year from the time the app is installed on the device. How do i make the program to recognize each new day as the app should retrieve one message from the database per day..  or how do i make the program to call a new message every time a day has begun??
Any help will be really appreciated... i'm still in the learning stages of iphone development.. so please guide me...
Thanks!!
|
Take a look at NSCalendar, NSDate, and NSDateComponents. Unless you want to support localizations that use non-roman calendars, you just use a Gregorian calendar object.
There are methods in NSCalendar that let you take an NSDate and convert it to components like month/day/year.
What I would do is to create a Gregorian calendar object. I'd use that to calculate the month/day/year of the first launch, and save that to NSUserDefaults.
I would then set up the app so that on every launch (or return to foreground, since that's what you usually get) I would calculate the day/month/year of the current date. I'd compare that to a "currentDay" entry in user defaults. If there was no current day record, or today's value is greater, I'd update the message.
After deciding if the current day is greater than the saved current day, I'd save the new day/month/year value to a "currentDay" record in user defaults.