1

I have to added a local notification for next 30 days(June-01-2013 t0 June-30-2013).

For Example:

I have to change the date on the "settings" to June-15-2013, and then I have to change the date to June-05-2013. The local notification not called for the (June-01 to June-15). After June-16 is working fine.

My question is

1) Any restrictions for the UILocalNotification to fire the past dates?

2) Is it possible to fire the local notification for past dates?

Please help me. Thanks in advance.

4

2 回答 2

3

苹果文档指出

如果指定的值为 nil 或者是过去的日期,则立即发送通知。

因此,如果您在过去设置本地通知的 fireDate,该通知将立即被触发。

另外,我认为您的情况很特殊,因为您手动更改了设备日期设置。更改时区时可能会更改日期设置,但您的情况不同,您没有更改时区,您只是更改日期,我认为您的新日期之前(过去)的本地通知被忽略。

于 2013-05-27T14:53:40.263 回答
2

好吧,这是我在对应用程序的健壮性进行 cam 测试时遇到的情况之一。我的应用程序还发布了未来日期的通知。一切顺利,如果用户不更改日期。但作为测试的一部分,将日期更改为未来和过去会禁用一些本应出现的通知。

我解决这种情况的方法是响应应用程序委托中的以下回调

-(void)applicationSignificantTimeChange:(UIApplication *)application

在这里,我根据当前日期的要求重新发布了所有通知。这在我的情况下起到了作用。这是一个繁重的解决方案,因为所有通知都必须删除并重新发布,但对我来说是必需的。

还有一种情况,您可能需要重新同步通知。用户可能还更改了应用关闭的日期。为此,我让应用程序在每次启动时重新同步通知。您可以通过检查日期是否有重大变化来优化此方法。

于 2013-05-27T16:12:23.700 回答