How to clear all the notifications from notification bar in iphone - iphone

I have to clear all the Remote/Local notifications from the notification bar when the user logs out from the app without clearing by his/her own. I'm using this code to clear the notifications but it isn't working for me this is my code:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

It seems your code is correct. Still you can try this.
[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
See this.

Related

iPhone: how to remove notification from notification center

I have a provider which sends Push notifications to my iPhone. If I'm on home screen, I click on push notification in notification center and my app become open. Then I close my app, but notification is still in notification center...Why ? I already read that, why its not disappear ? How to remove this notification after I close my app ??
WHen are you want to remove the badge from the application just value of the badge number assign to 0 is means automatically remove the badges.
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
You can remove the notifications using the below code
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
This will remove all the app's notification from Notification Center.

UILocalNotification not showing up in Notification Center when app is in background

I have a GPS app that registers to run in the background. I also show a UILocalNotification when I have finished a process. This correctly shows, and if the app is open, then it also appears in Notification Center (swipe down from top). But, if I call the UILocalNotification when my app is in the background, or the screen is locked, I DO get the notification, but it does NOT show up in Notification Center.
I am correctly registering for notifications in my app delegate (iOS 5 bug workaround):
// Register for notifications
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
Calling the notification:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.alertBody = msg;
localNotif.alertAction = NSLocalizedString(#"View", nil);
localNotif.soundName = #"alert.caf";
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];
Is this a bug? Why would it show up in Notification Center only when my app is open, even though the notification is shown to the user, and not other times?
Are you also using push notifications? I believe there is no need to call registerForRemoteNotificationTypes: if you are only using local.
Check Here
From the look of the code you posted, it does not look like the code would run in the background. It looks like you are trying to present a Local Notification when an even occurs in the background. You can not do this. Local Notifications are meant to be scheduled while the app is running to go off at a later time when the app is not running, and then they will trigger even when the app is closed.
You need to use Push Notifications. Check out Apple's documentation here.
EDIT: Is your app enabled for the notification center in settings?
have you added the UIBackgroundModes key to your Info.plist file ?
You need to have the UIBackgroundModes Key set to location.

Push notification badges not appearing?

I'm using Urban Airship to send push notifications to my app
eg:
{"aps": {"badge": 2, "alert": "Part 2 of the August Issue is ready to download!", "sound": "default"}, "device_tokens": ["X"]}
The alert will display perfectly, however the app icon is never badged regardless of what I set "badge":# to...
Is my payload incorrect or is there extra code I'm supposed to add to my app to handle badges as well as alerts? Thanks!
EDIT:
I'm registering for push notifications like this:
// Register for notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
I was running with a similar problem. After a few minutes of checking around. I notice that there was a problem with my server side code. I found out that badge value has to be implicitly set as an integer to get the desired result. Hope that helps anyone reading this.
set the following code in the appdelegate .m file..
-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
//[self addMessageFromRemoteNotification:userInfo];
NSString* alertValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
NSLog(#"my message-- %#",alertValue);
int badgeValue= [alertValue intValue];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];
}
In iOS 5 there is a Settings -> Notifications. Double check that the Badge App Icon is turned on.
I assume that the app is not in the foreground when you were testing? It if is in the foreground then you have to handle badging manually.

badge number count increament

I have implemented the local notification concept, it is working properly but there is a problem in badge number it is not increamenting automatically as notifications occurs. I have got a link where solution for this problem is given but don't know how to use it in app delegate. Following is the link... If someone know how to auto increament the badge number ,please provide me some solution.
https://github.com/csheldrick/UILocalNotification
Thanku very much.
When you create your local notification then before registring it with the system add this line of code.
localNotif.applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber+ 1;
and then you register you notification with the system
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
localNotif is object of UILocalNotification
Hope this helps
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[UIApplication sharedApplication].applicationIconBadgeNumber=application.applicationIconBadgeNumber+1;
}
i hope it will help ful to you

Piling up UILocalNotifications

I'm developping an app that sends tips to users every five minutes through UILocalNotifications. The problem is that if you don't use your phone for a while, the notifications pile up and when you unlock the phone, you have to dismiss them one after the other, which can become quite annoying if you haven't used the phone for quite a while. Clicking the action button on the Alert sends you back to the application but even then, you still have to go through all the notifications.
Is there any means of dismissing all the notifications that have already been fired with a single click ?
Thanks for your help.
Miky Mike
Well, actually, I realize I made a mistake.
In order to cancel all the UIlocalNotifications at one, I just have to create this simple method : one line of code is enough :
- (void)application:(UIApplication *)app didReceiveLocalNotification :(UILocalNotification *)notification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
and there you are. Thanks anyway.
Before scheduling the next alarm you better to cancel all the previous notifications and then set the new one,
UIApplication* app = [UIApplication sharedApplication];
NSArray* oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];