确定是否发生了日变化 [英] 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.
推荐答案
当你的应用程序运行时,你可以听对于 UIApplicationSignificantTimeChangeNotification 通知并测试当天收到的时间。当您的应用程序退出时,您可以将当天保存到您的首选项,当应用再次启动时,您可以在当天测试保存的日期。
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.
您可以使用 NSDateComponents 。
这篇关于确定是否发生了日变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!