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

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

iphone - Removing badge from iOS app icon

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...