2
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];'

I added the above code to didfinishLaunchingWithOptions but when a user taps a notification in his notification center and enters my app the notification does not gets cleared.

Edit:

I also tried adding this to my code:

You Also need to increment then decrement the badge in your application:didReceiveRemoteNotification: method if you are trying to clear the message from the message centre so that when a user enters you app from pressing a notification the message centre will also clear, ie:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications]; 

as describes here: iOS application: how to clear notifications? but the notification still won't clear from the notification center

asked Jan 29, 2013 at 10:40

3 Answers 3

5

I just Added a Badge number manually to my application and pasted

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

To my AppDelegate. For me this works like a charm. Note that didfinishLaunchingWithOptions and applicationDidBecomeActive are not the same as Mouhammad Lamaa explained. If you paste this to your AppDelegate and tap the notification in notification center it should disapper. If it does not your App maybe creates a new Notification after becoming active?

answered Jan 29, 2013 at 12:17
Sign up to request clarification or add additional context in comments.

Comments

0

add this code

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

the didfinishlaunchingwithoptions launched at the initial launch of your app. if your app the running in the background, didfinishlaunchingwithoptions will not be launched.

answered Jan 29, 2013 at 10:49

1 Comment

I have one notification in the nc and my app Is closed. Touching the notification would lunch the app but won't remove the notification. What you suggested is a good idea , if the 'remove' would work..
0

When the user open application from notification action - it launches with

- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 UILocalNotification *remoteNotif =
 [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
 if (remoteNotif) {
 //handle remote notification
 }
 ....
}

But when the app was in background it calls

- application:didReceiveRemoteNotification:

Also method [[UIApplication sharedApplication] cancelAllLocalNotifications]; cancel registered LOCAL notifications only. Push notifications can't be canceled - they delivered immediately and executed only once.

answered Jan 29, 2013 at 14:13

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.