开发者

cancelAllLocalNotifications in applicationWillTerminate?

I want to cancelAllLocalNotifications and setApplicationIconBadgeNumber to 0 when my application is terminated (either by the OS or by double tapping the home button and killing the app). I simply added these two calls to my开发者_运维问答 primary app delegate code:

-(void)applicationWillTerminate:(UIApplication *)application 
{
        [application cancelAllLocalNotifications];
        [application setApplicationIconBadgeNumber:0];
}

Existing notifications are still running and the badge number remains set?


applicationWillTerminate: is not called by the OS when it kills your app. The OS just kills the process without notifying your app about it. There is no documented way to execute code at this moment.


You should use applicationWillResignActive: instead.

Starting with iOS 4.0 applicationWillTerminate is not called for applications when they are killed in the background. Apps are put in the background when you hit the home button now or otherwise switch apps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜