Determine if day change has occurred
I would like to create a notifciation that occurs every time a new day has occurred locally (either while using the app, or if it occurs in between launches). I was wondering what might be the best way to go about observing this change.
- Handling multiple UISwitch controls in a table view without using tag property
- CoreText crashes when run in multiple threads
- Two button simultaneous press input
- Is it possible to cache resources loaded in an iPhone UIWebView?
- How to use iOS Simulator 7 \ XCode 5 to test pre-iOS 7 UI (without upgrading the app for iOS 7)
- Xcode: Is there a location/flag to prevent a Class from compiling?
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:
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.
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.
- modifying a plist is not working
- Autoimplement Swift protocol methods in XCode
- iOS Enterprise OTA distribution Unable to Download Application
- Why does isEqualToString not work for NSString?
- How to find a Clang warning flag in Xcode that's not present in build logs
- Visual Studio style XML Documentation in XCode?
- AVAudioPlayer on Lock Screen
- SKScene iPad height width reversed
- BSXPCMessage received error for message: Connection interrupted
- Swift: Draw on image without changing its size (Aspect fill)
- “isEqualToString” Cocoa error
- FacebookDisplayName on iOS with german umlauts
- Xcode 9 – iOS 11 UITableView rows are empty
- memory usage increases dramatically after each FMDB query
- How to sort array based on another arrays position?