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

发布于 2024-10-16 09:17:22 字数 373 浏览 5 评论 0原文

我的应用程序有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

携君以终年 2024-10-23 09:17:22

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

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

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

  /* Other code here */
  ...
}

当然,实现您自己的 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:

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

  /* Other code here */
  ...
}

of course, implement your own firstRun setter and getter to fetch/save into persistent storage, like NSUserDefaults.

再见回来 2024-10-23 09:17:22

这实际上是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文