Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to judge whether it is a new day in an iOS project?

I have a UIView ,I want it to display in a new day.For example,today I launch my app,and that UIView comes to my view,but after this,I can't see that UIView until tomorrow.

So I want to know how to judge whether it is a new day to display the UIView?

like image 585
lixiaoyu Avatar asked Oct 30 '12 00:10

lixiaoyu


1 Answers

You need to register for the UIApplicationSignificantTimeChangeNotification notification.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeChange) name:UIApplicationSignificantTimeChangeNotification object:nil];

Then in the timeChange method (or whatever you call it) update your view.

Don't forget to unregister:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationSignificantTimeChangeNotification object:nil];

This notification is sent at midnight, if the user changes the time on their device, or the timezone changes. If your app is in the background when the change happens, it will get notified when the app returns to the foreground.

like image 93
rmaddy Avatar answered Nov 13 '22 04:11

rmaddy