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.
On your iPhone, iPad, or iPod touchTurn on Set Automatically1 in Settings > General > Date & Time. This automatically sets your date and time based on your time zone. If a message appears saying that updated time zone information is available, restart your device and any paired Apple Watch.
Go to Settings/General/Date & Time and make sure you have Set Automatically turned on. Also go to Settings/Privacy/Location Services.
Tap Settings to open the Settings menu. Tap Date & Time. Tap Automatic. If this option is turned off, check that the correct Date, Time and Time Zone are selected.
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With