Enz*_*ran 6 iphone notifications repeat alarm uilocalnotification
我的应用程序具有使用UILocalNotification的警报功能,效果很好.但是,如果用户卸载应用程序,然后重新安装它,他将立即收到所有"中间"通知.
我试过打电话:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Run Code Online (Sandbox Code Playgroud)
如果它是第一次启动应用程序,但它没有帮助,因为甚至在应用程序之前收到通知:didFinishLaunchingWithOptions:被调用.
即使用户删除了应用程序,当重复警报时,这在4.0中更糟,但至少该错误是Apple在以后的版本中修复的.但是现在我坚持这个.有人有想法吗?
Ken*_*Cal 15
根据Apple的说法,这不是一个错误(我提交了一个错误报告).系统会保留24小时未安装应用程序的UILocalNotifications,以防用户意外删除应用程序,并在该时间范围内重新安装应用程序时恢复所述UILocalNotifications.
解决方案是在首次启动时删除所有UILocalNotifications,如下所示:
- (BOOL) application: (UIApplication*) application
didFinishLaunchingWithOptions: (NSDictionary*) launchOptions
{
if (self.isFirstRun)
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
self.firstRun = NO;
}
/* Other code here */
...
}
Run Code Online (Sandbox Code Playgroud)
当然,实现自己的firstRunsetter和getter来获取/保存到持久存储中,比如NSUserDefaults.
这实际上是iPhone中的一个错误.如果您删除了应用程序并在以后安装它,它将具有相同的应用程序ID,因此当重新安装应用程序时,即使您没有打开应用程序,也会触发所有过去的本地通知.
| 归档时间: |
|
| 查看次数: |
2268 次 |
| 最近记录: |