简体   繁体   English

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

[英]UILocalNotification fires after reinstalling the app

My app has an alarm function using UILocalNotification, and it works great.我的应用程序有一个使用 UILocalNotification 的闹钟功能,而且效果很好。 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.如果这是第一次启动应用程序,但它没有帮助,因为甚至在 application:didFinishLaunchingWithOptions: 被调用之前就收到了通知。

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.这在 4.0 中更糟,即使用户删除了应用程序也会重复警报,但至少苹果在以后的版本中修复了这个错误。 However now I'm stuck with this.但是现在我坚持这个。 Anyone has an idea?有人有想法吗?

According to Apple, this is not a bug (I filed a bug report).根据 Apple 的说法,这不是错误(我提交了错误报告)。 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.系统会将已卸载应用程序的 UILocalNotifications 保留 24 小时,以防用户意外删除该应用程序,并在该时间范围内重新安装该应用程序时恢复所述 UILocalNotifications。

The solution would be to remove all UILocalNotifications on first startup, like so:解决方案是在第一次启动时删除所有 UILocalNotifications,如下所示:

- (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 .当然,实现你自己的firstRun setter 和 getter 来获取/保存到持久存储中,比如NSUserDefaults

This is actually a bug in iPhone.这实际上是 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.如果您删除该应用程序并稍后安装它,它将具有相同的应用程序 ID,因此当重新安装该应用程序时,即使您没有打开该应用程序,也会触发所有过去的本地通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当UILocalNotification触发时,将应用程序从后台自动带到前台吗? - Bringing an app from background to foreground automatically when an UILocalNotification fires? 在iOS应用中触发UILocalNotification后的调用方法 - Call method after UILocalNotification fired in iOS app 重新启动应用程序或关闭应用程序后,计划的UILocalNotification不触发 - Scheduled UILocalNotification does not fire after when restarting app or closing app 删除并重新安装应用后,InAppPurchase 停止接收 productRequest 响应 - InAppPurchase stop receiving the productRequest response after deleting and reinstalling app UILocalNotification - 打开应用程序后警报声继续播放 - UILocalNotification - alert sound keeps playing after opening app 删除并重新安装iphone应用程序后接收本地通知 - Receive local notifications after deleting and reinstalling an iphone app UILocalNotification 立即触发,而不是在预定时间触发 - UILocalNotification fires immediately instead of at scheduled time 在UILocalNotification之后加载视图 - Loading views after the UILocalNotification Birthday App iOS中的UILocalNotification - UILocalNotification in Birthday App iOS UILocalNotification我的警报每分钟触发一次迅速2.0 - UILocalNotification my alert fires every minute swift 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM