Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In this application that I'm trying to make, I use push notifications. This part works just fine. When I send a notification I also add a badge to the app icon. The problem is when I lunch the application it should disappear again, but it does not.

-(IBAction)Push{

    NSMutableDictionary *data = [NSMutableDictionary dictionary];

    [data setObject:@"Numfeud: Troels made a move!" forKey:@"alert"];

    [data setObject:[NSNumber numberWithInt:1] forKey:@"badge"];

    [data setObject:@"bar" forKey:@"foo"];

    [PFPush sendPushDataToChannelInBackground:@"GameChannel2" withData:data];
}

In the application didFinishLaunchingWithOptions I try to set badge to 0 in this way:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

How can I clear the application icon badge?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
328 views
Welcome To Ask or Share your Answers For Others

1 Answer

If your app becomes active again and is still in the background you should reset the badge count in -applicationDidBecomeActive: as well:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    application.applicationIconBadgeNumber = 0;
}

If your app is still running in the background -application:didFinishLaunchingWithOptions: won't be called.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...