can my application get any notification when device timezone changed? I want to get a notification when my application is foreground. NSTimezone does not worked for me as i have to continuously check for timezone.
-
check this https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimeZone_Class/Reference/Reference.html – Chirag Pipaliya May 03 '13 at 07:07
-
check this http://stackoverflow.com/questions/13741585/notify-app-when-ipad-date-time-settings-changed – Chirag Pipaliya May 03 '13 at 07:10
2 Answers
UIApplicationDelegate
has a method called applicationSignificantTimeChange:
that gets called when there is a significant change in the time.
The examples listed in the documentation are:
Examples of significant time changes include the arrival of midnight, an update of the time by a carrier, and the change to daylight savings time
But I would assume that timezone changes count as a significant time change.
The docs also say that if the time change happens when your app is in the background you will get it when you go to the foreground
If your application is currently suspended, this message is queued until your application returns to the foreground, at which point it is delivered.
You can also listen for UIApplicationSignificantTimeChangeNotification
to be posted to get the same information anywhere else in your app.

- 56,267
- 18
- 167
- 205
-
I notice that the observer method is invoked when the app is put in foreground and NOT and not in the duration when the app is in the background and the user changes the timezone or moves to a different timezone. Is that the expected behavior? On Android, such broadcasts are sent to the app even if the app is in background but I realize they are two different OSes with a very different design. – Varun Gupta Nov 25 '16 at 10:42
-
Just noticed here https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622992-applicationsignificanttimechange that it is in fact delivered when the is in the foreground. I guess now I need to find a way if I can figure it out while the app is in the background. Maybe use the background fetch to achieve it. – Varun Gupta Nov 25 '16 at 13:31
-
All iOS notifications you observe are queued until the app comes to the foreground. If you need to handle something specifically while the app is in the background, you can do the background fetch. You'll need to get an "entitlement" from Apple in order to do actual background processing. – leanne Mar 18 '17 at 15:46
Just listen to
NSSystemTimeZoneDidChangeNotification
.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeZoneChanged) name: NSSystemTimeZoneDidChangeNotification object:nil];
And remember to unregister, for example in dealloc method.
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSSystemTimeZoneDidChangeNotification object:nil];

- 3,059
- 27
- 37
-
I notice that the observer method `timeZoneChanged here` is invoked when the app is put in foreground and NOT and not in the duration when the app is in the background and the user changes the timezone or moves to a different timezone. Is that the expected behavior? On Android, such broadcasts are sent to the app even if the app is in background but I realize they are two different OSes with a very different design. – Varun Gupta Nov 25 '16 at 10:42
-
1