Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 为什么更改时区后NSTimeZone返回旧时区_Objective C_Nstimezone - Fatal编程技术网

Objective c 为什么更改时区后NSTimeZone返回旧时区

Objective c 为什么更改时区后NSTimeZone返回旧时区,objective-c,nstimezone,Objective C,Nstimezone,我最小化以放置我的应用程序,然后更改时区,然后打开应用程序NSTimeZone返回时区的旧值。 如果我最小化到托盘并再次打开时区,则返回新值。我怎样才能修好它 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadVC)

我最小化以放置我的应用程序,然后更改时区,然后打开应用程序NSTimeZone返回时区的旧值。 如果我最小化到托盘并再次打开时区,则返回新值。我怎样才能修好它

 [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reloadVC)
                                                 name:UIApplicationWillEnterForegroundNotification
                                               object:nil];
-(void) reloadVC{
    NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
    NSLog(@"%@", currentTimeZone);
}

如果进入前台时您计划做的只是捕捉时区变化,请遵守此通知:

当您的应用程序进入前台时,此通知将排队等待处理,因此您不需要单独的观察者进入前台

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reloadVC)
                                             name:NSSystem​Time​Zone​Did​Change​Notification
                                           object:nil];
-(void) reloadVC{
    NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
    NSLog(@"%@", currentTimeZone);
}