【问题标题】:Why after change Timezone NSTimeZone return old Timezone为什么更改时区 NSTimeZone 后返回旧时区
【发布时间】:2017-03-18 13:46:58
【问题描述】:

我最小化到托盘我的应用程序,然后更改时区,然后打开应用程序 NSTimeZone 返回时区的旧值。 如果我最小化到托盘并再次打开时区返回新值。我该如何解决?

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

【问题讨论】:

    标签: objective-c nstimezone


    【解决方案1】:

    如果您在进入前台时只打算捕捉时区变化,请注意以下通知:NSSystem​Time​Zone​Did​Change​Notification

    当您的应用进入前台时,此通知将排队等待处理,因此您无需单独的观察者即可进入前台。

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

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多