Xcode iOS7 监听时间改变的通知来刷新界面

当新的一天来到,或者说当运营商时间更新的时候,UIApplication会下发一个通知来告诉你时间改变了。可以在程序中监听

UIApplicationSignificantTimeChangeNotification 事件来对界面进行更新或者做任何你需要做的事。


当系统的区域格式,或者时间格式(是否24小时制)改变时,UIApplication也会下发一个通知来告诉你这个变化。可以在程序中监听 

NSCurrentLocaleDidChangeNotification事件来对界面进行更新或者做任何你需要做的事


代码如下:

- (void)significantTimeChange
{
    // todo: Refresh the interface.
}

- (void)currentLocaleDidChange
{
    // todo: Refresh the interface.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter] addObserver:self 
					     selector:@selector(significantTimeChange) 
						 name:UIApplicationSignificantTimeChangeNotification 
					       object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
					     selector:@selector(currentLocaleDidChange) 
						 name:NSCurrentLocaleDidChangeNotification 
					       object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


你可能感兴趣的:(iOS)