Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local notifications not adjusting for timezones

Tags:

ios

I'm scheduling a local notification with an NSDate with the time set to 9pm and am setting the notification's timezone to UTC/GMT.

If I set the device timezone to UTC (and time to 8.59pm) then the notification fires at 9pm as expected.

However if I set the device timezone to West Coast US (i.e. set it to Seattle or Cupertino or PDT directly etc.) and set the time to 1.59pm, or set the device timezone to East Coast US and set the time to 4.59pm, then the notification does not fire at 2pm or 5pm respectively.

But I was expecting it should do because when it is 9pm UTC then with the current daylight saving at this time of year 9pm UTC is equivalent to 5pm Eastern and 2pm Western.

If I set the time on the device to 8.59pm while the device timezone is PDT then the notification will fire at 9pm, even though I have set the timezone in the notification to UTC/GMT, this is not correct because 9pm PDT is not 9pm UTC.

Therefore it seems to me the OS is ignoring the notification's timezone that I am setting. Does anybody have any explanation why its not working as expected?

Thanks

like image 457
Gruntcakes Avatar asked Aug 03 '12 18:08

Gruntcakes


1 Answers

See the documentation of the timeZone property of UILocalNotification:

... If you assign a valid NSTimeZone object to this property, the fire date is interpreted as a wall-clock time that is automatically adjusted when there are changes in time zones; an example suitable for this case is an an alarm clock.

So I assume that if you want an absolute time for the notification, you must not assign a time zone.

like image 81
Martin R Avatar answered Oct 03 '22 03:10

Martin R