I want to update the timezone of my iOS app while its running. I want to update the timezone when user change region from the "Settings" app "Settings->General->Language & Region->Region".
I am receiving region change notification using and NSCurrentLocaleDidChangeNotification and selector method "updateTimeZone" is being called.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTimeZone) name:NSCurrentLocaleDidChangeNotification object:nil];
- (void)updateTimeZone
{
NSLog(@"Zone1: %@", [NSTimeZone systemTimeZone]);
NSLog(@"Zone2: %@", [NSTimeZone localTimeZone]);
NSLog(@"Zone3: %@", [NSTimeZone defaultTimeZone]);
[NSTimeZone resetSystemTimeZone];
NSLog(@"Zone11: %@", [NSTimeZone systemTimeZone]);
NSLog(@"Zone22: %@", [NSTimeZone localTimeZone]);
NSLog(@"Zone33: %@", [NSTimeZone defaultTimeZone]);
}
Output
2015-01-07 16:23:02.992 A[1677:105206] Zone1: Asia/Kolkata (GMT+5:30) offset 19800
2015-01-07 16:23:02.993 A[1677:105206] Zone2: Local Time Zone (Asia/Kolkata (GMT+5:30) offset 19800)
2015-01-07 16:23:02.994 A[1677:105206] Zone3: Asia/Kolkata (GMT+5:30) offset 19800
2015-01-07 16:23:02.999 A[1677:105206] Zone11: Asia/Kolkata (GMT+5:30) offset 19800
2015-01-07 16:23:02.999 A[1677:105206] Zone22: Local Time Zone (Asia/Kolkata (GMT+5:30) offset 19800)
2015-01-07 16:23:03.001 A[1677:105206] Zone33: Asia/Kolkata (GMT+5:30) offset 19800
I tried to change many regions from Settings but my application always shows my current time zone. I am already using [NSTimeZone resetSystemTimeZone]; to remove the cached timezone but still always getting my current time zone. How can I fetch the timezone set in iOS region (systemtimezone)?
When we update region, it updates the locale(AM/PM or 24HOUR format) for the device. We can get this updated locale in application using [NSLocale autoupdatingCurrentLocale] but we need to pop the view controller from navigation controller and push it again for the new locale. I want to update this new time format without pop out of view-controller from navigation controller?