Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UILocalNotification延迟1小时_Ios_Objective C_Nsdate_Uilocalnotification_Nstimezone - Fatal编程技术网

Ios UILocalNotification延迟1小时

Ios UILocalNotification延迟1小时,ios,objective-c,nsdate,uilocalnotification,nstimezone,Ios,Objective C,Nsdate,Uilocalnotification,Nstimezone,我个人并没有遇到过这个问题,但对于我的许多用户来说,一次设置的通知实际上是在一小时后触发的 以下是我用来生成通知的代码: UILocalNotification *notif = [[UILocalNotification alloc] init]; notif.fireDate = date; notif.timeZone = [NSTimeZone defaultTimeZone]; notif.alertBody = @"Alert time!"; notif.alertAction =

我个人并没有遇到过这个问题,但对于我的许多用户来说,一次设置的通知实际上是在一小时后触发的

以下是我用来生成通知的代码:

UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.fireDate = date;
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Alert time!";
notif.alertAction = @"Wake me";

[[UIApplication sharedApplication] scheduleLocalNotification:notif];

相当标准。出现问题的用户在英国时间,英国时间有夏令时。我想知道这是否是某种类型的iOS错误?

我认为问题与iOS存储时区缓存有关。这个功能有点让人困惑,因为你可以拥有3个不同的时区(如果其中一半让你困惑,请不要担心):

[NSTimeZone defaultTimeZone]

返回当前应用程序的默认时区。如果未设置默认时区,此方法将调用systemTimeZone并返回系统时区。默认时区是应用程序运行时使用的时区,您可以对其进行更改(这样您就可以使应用程序像在其他时区一样运行)

[NSTimeZone localTimeZone]

返回一个对象,该对象将所有消息转发到当前应用程序的默认时区。本地时区始终表示默认时区的当前状态。本地时区添加了一个间接级别,每当您对其调用方法时,它的行为就好像它是当前默认时区一样

[NSTimeZone systemTimeZone]

返回系统当前使用的时区。如果获得系统时区,则应用程序会缓存该时区,并且如果用户随后更改系统时区,则不会更改该时区。下次调用systemTimeZone时,您将返回原来的时区。您必须调用resetSystemTimeZone来清除缓存对象

这整件事让我个人感到困惑。但是,
resetSystemTimeZone
方法似乎很有趣:

如果应用程序缓存了系统时区,此方法将清除该缓存对象。如果随后调用systemTimeZone,NSTimeZone将尝试重新确定系统时区,并将创建和缓存一个新对象

考虑到用户可能在时区之间移动,当一些时区支持夏令时,而另一些不支持夏令时,并且考虑到苹果自己在这方面一直存在问题,似乎合乎逻辑的解决方案是尽可能使夏令时不易中断

Non breakable意味着我在整个应用程序中使用systemTimeZone,并且在每次提到它之前都在行中使用
resetSystemTimeZone

UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.fireDate = date;
[NSTimeZone resetSystemTimeZone];
notif.timeZone = [NSTimeZone systemTimeZone];

到目前为止,我还没有遇到任何问题。希望这会对某人有所帮助。

当您从另一个变量分配
fireDate
时,您可能在存储时间方面有问题……也许您将其保存在
CoreData
中?
date
等于什么?