重新安装应用程序后 UILocalNotification 触发
我的应用程序有一个使用 UILocalNotification 的闹钟功能,而且效果很好。但是,如果用户卸载该应用程序,然后重新安装它,他将立即收到所有“中间”通知。
我尝试调用:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
如果这是应用程序第一次启动,但它没有帮助,因为甚至在调用 application:didFinishLaunchingWithOptions: 之前就收到了通知。
在 4.0 中情况更糟,即使用户删除了应用程序,警报也会重复出现,但至少 Apple 在以后的版本中修复了该错误。然而现在我被这个问题困住了。有人有主意吗?
My app has an alarm function using UILocalNotification, and it works great. However, if the user uninstalls the app, then later REINSTALLS it, he would receive all the "in between" notifications at once.
I have tried to call:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
if it's the first time the app is launched, but it doesn't help, because the notification is received even before application:didFinishLaunchingWithOptions: is called.
This was worse in 4.0 when the alarm was repeated even if the user has deleted the app, but at least that bug was fixed by Apple in later release. However now I'm stuck with this. Anyone has an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据苹果公司的说法,这不是一个错误(我提交了一份错误报告)。系统会将已卸载应用程序的 UILocalNotifications 保留 24 小时,以防用户意外删除该应用程序,并在该时间范围内重新安装该应用程序时恢复所述 UILocalNotifications。
解决方案是在首次启动时删除所有 UILocalNotifications,如下所示:
当然,实现您自己的
firstRun
setter 和 getter 来获取/保存到持久存储中,例如NSUserDefaults
。According to Apple, this is not a bug (I filed a bug report). The system retains the UILocalNotifications for uninstalled apps for 24 hours just in case the user deleted the app by accident, and restores the said UILocalNotifications if the app is re-installed within that time frame.
The solution would be to remove all UILocalNotifications on first startup, like so:
of course, implement your own
firstRun
setter and getter to fetch/save into persistent storage, likeNSUserDefaults
.这实际上是 iPhone 的一个 bug。如果您删除了该应用程序并稍后安装,它将具有相同的应用程序 ID,因此当重新安装该应用程序时,即使您没有打开该应用程序,所有过去的本地通知也会被触发。
This is actually a bug in iPhone. If you removed the application and install it later also, it will have same app id, so when the application is reinstalled all the past local notifications were fired even if you didn't open the app.