iphone - 重新安装应用程序后 UILocalNotification 触发

标签 iphone notifications repeat alarm uilocalnotification

我的应用程序有一个使用 UILocalNotification 的闹钟功能,并且效果很好。但是,如果用户卸载该应用程序,然后重新安装它,他将立即收到所有“中间”通知。

我尝试调用:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

如果这是应用程序第一次启动,但它没有帮助,因为甚至在调用 application:didFinishLaunchingWithOptions: 之前就收到了通知。

在 4.0 中情况更糟,即使用户删除了应用程序,警报也会重复出现,但至少 Apple 在以后的版本中修复了该错误。然而现在我被这个问题困住了。有人有想法吗?

最佳答案

根据苹果公司的说法,这不是一个错误(我提交了一个错误报告)。系统会将已卸载应用程序的 UILocalNotifications 保留 24 小时,以防用户意外删除该应用程序,并在该时间范围内重新安装该应用程序时恢复所述 UILocalNotifications。

解决方案是在首次启动时删除所有 UILocalNotification,如下所示:

- (BOOL)          application: (UIApplication*) application
didFinishLaunchingWithOptions: (NSDictionary*)  launchOptions
{
  if (self.isFirstRun)
  {
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    self.firstRun = NO;
  }

  /* Other code here */
  ...
}

当然,实现您自己的 firstRun setter 和 getter 来获取/保存到持久存储中,例如 NSUserDefaults

关于iphone - 重新安装应用程序后 UILocalNotification 触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4923028/

相关文章:

jquery - 尝试结合使用 CSS、jQuery 和 HTML 来创建可重复的 mouseenter/mouseleave 函数

ios - 在 UIView 上绘制自定义圆角矩形 UIBezierPath

iphone - iPhone SDK 中的自动调整大小如何工作?

iphone - 在 UIScrollView 中禁用垂直滚动

android - 单击持续通知时返回上一个 Activity

matlab - 通过多次合并相同的行向量来构建矩阵

iphone - 您可以在 iTunes Connect 中自动注册新产品(应用程序内购买)吗?

java - 当应用程序被终止或从一加 3t 手机上最近的应用程序中滑出时,Android FCM 推送通知不起作用

android - 如何在没有振动的情况下在delphi XE10 seattle中触发通知

android - AlarmManager 在应用程序销毁时被杀死