本文介绍了本地通知未针对时区进行调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在计划将NSDate的本地通知的时间设置为9pm,并将通知的时区设置为UTC/GMT.

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.

如果我将设备时区设置为UTC(时间设置为8.59pm),则通知将按预期在晚上9点触发.

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

但是,如果我将设备时区设置为美国西海岸(即直接将其设置为Seattle或Cupertino或PDT等)并将时间设置为1.59pm,或者将设备时区设置为美国东海岸并将时间设置为4.59pm,则通知不会分别在2pm或5pm触发.

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.

但是我期望这样做,因为现在是夏令时(UTC)晚上9点,那么现在夏令时(UTC)的当前夏令时是晚上9点(UTC),相当于东部时间下午5点,西方时间下午2点.

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.

如果在设备时区为PDT时将设备上的时间设置为8.59pm,那么即使我在通知中将时区设置为UTC/GMT,通知也会在晚上9点触发,这是不正确的,因为PDT晚上9点不是世界标准时间晚上9点.

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?

谢谢

推荐答案

请参见UILocalNotificationtimeZone属性的文档:

所以我假设,如果您想要一个绝对的通知时间,则必须指定一个时区.

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

这篇关于本地通知未针对时区进行调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:23