[英]Removing Local Notifications when app has been terminated
In my app, I set up local notifications to notify the user while the app is running. 在我的应用程序中,我设置了本地通知,以在应用程序运行时通知用户。 In order to clean these up in case the app is terminated, I have set up
applicationWillTerminate:
to clear these notifications: 为了清除这些错误,以防应用终止,我设置了
applicationWillTerminate:
来清除这些通知:
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"applicationWillTerminate");
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
Unfortunately, if the app crashes, or I terminate debugging, this function isn't called and therefore I still get the local notifications delivered to the device. 不幸的是,如果应用程序崩溃或我终止调试,则不会调用此函数,因此,我仍然将本地通知传递给设备。
Is there a way of definitely checking if the application has quit unexpectedly so I can tidy these up? 有没有一种方法可以肯定地检查应用程序是否意外退出,以便我进行整理?
I'm using this KSCrash library with great success. 我正在使用此KSCrash库取得巨大成功。 Maybe it can help you also:
也许它还可以帮助您:
https://github.com/kstenerud/KSCrash
Or alternatively, have you set UIApplicationExitsOnSuspend
on your .plist file? 或者,是否在.plist文件上设置了
UIApplicationExitsOnSuspend
? If you don't, there is no guarantee that applicationWillTerminate
will be called, when using iOS 4. 如果不这样做,则无法保证在使用iOS 4时将调用
applicationWillTerminate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.