且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何处理iOS上的时间事件?

更新时间:2022-11-05 16:11:48

在您的应用委托中,实现以下方法:
- (void)applicationSignificantTimeChange:(UIApplication *)应用程序



当日变化时,或者由于任何原因(例如时区更改),设备的时间已经在后台更改,此方法被调用。


I'm coding an iPad app, and I have to change a graphic when the day changes to Sunday.

My straightforward solution is to check the day in the - (void)applicationDidBecomeActive:(UIApplication *)application or -(void)viewWillAppear:(BOOL)animated methods, and set a timer like every 10 mins to check if the day have changed to Sunday while the app is active.

Is there another, perhaps more efficient, way to handle this?

In your appliciation delegate, implement the following method: -(void)applicationSignificantTimeChange:(UIApplication *)application

This method is called when the day changes, or if the device's time has been changed in the background for whatever reason (such as changes to time zone).