Determine if day change has occurred

4 Solutions Collect From Internet About “Determine if day change has occurred”

While your app is running, you can listen for the UIApplicationSignificantTimeChangeNotification notification and test the current day when you receive that. When your app quits, you can save the current day to your preferences, and when the app launches again, you can test the saved day against the current day.

You can get information about the current day using NSDateComponents.

As mentioned in the other thread, as of iOS8, you can also directly listen to NSCalendarDayChangedNotification.

Check out :
Erica Sadun Time Utililties

There are some useful methods there for checking dates.

Alternatively you can look at UILocalNotifcations

You could schedule a local notification with a repeatInterval of one day.

It all depends on what you want to do but those are some options.

I’d probably do two things:

  1. While the app is running, have an NSTimer set to poll the current date [NSDate date] at a given interval. Store the value of the last date someplace (even in the user defaults) and then compare the new time to the stored time to check for a new day.

  2. When closing/quitting the app, store the current date and time in the same manner above. Then, when launching the app or bringing it to the foreground, check the current date against the stored date.

NSDateComponents, NSCalendar and NSDate will come in handy for this.