Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get notification on timezone change in iOS

Tags:

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.

like image 606
user2070826 Avatar asked May 03 '13 06:05

user2070826


People also ask

How do I get my iPhone to change time zones automatically?

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.

Why is my iPad not changing time zones?

Go to Settings/General/Date & Time and make sure you have Set Automatically turned on. Also go to Settings/Privacy/Location Services.

How do you turn off automatic Time?

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.


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.

like image 187
David Rönnqvist Avatar answered Oct 30 '22 18:10

David Rönnqvist


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];
like image 44
Juraj Antas Avatar answered Oct 30 '22 17:10

Juraj Antas