iPhone: how to remove notification from notification center - iphone

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.

Related

How to clear all the notifications from notification bar in 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.

How to remove Single Remote notification in iphone

I am developing game which have support of server side push notification of score and winning notification, User game request.
All is working fine with notification read and response store to device side. But when notification is pushing to notification center. when i click on notification at that time it remove all the push notification from notification center with following code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
But i want to remove selected remote notification from notification center.
Is there any way to remove single remote notification.Please help me.
Thanks in advance.
To cancel local notifications
If you have the means to obtain a reference to the specific UILocalNotification instance you want to cancel, you can call cancelLocalNotification: on it.
Try traversing all scheduled notifications in order to obtain that reference by going through:
NSArray *scheduledNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
To cancel remote notifications
This is entirely up to the server, can't be done without proper API on the server's side.

Method [[UIApplication sharedApplication] scheduledLocalNotifications] gets count = 0

My app is registered for receive push notification.
I've send 3 or 4 push notification that are listed in the Notification Center; the problem is that when I try to obtain this list (inside of my application) whit this method
[[[UIApplication sharedApplication] scheduledLocalNotifications] count]
they return me 0.
But this is wrong because I can see in the NC the list of notification.
Maybe this isn't the right way to obtain the list of notification... I don't know !
Any ideas ?
[[UIApplication sharedApplication] scheduledLocalNotifications] will give you your local scheduled notifications.
I'm not sure if there is an equivalent way to retrieve your push notifications since they reside on a server.

remove push notification once it is accepted by user

I am pushing some text to an iPhone app. once the message is accepted and processed in the app I still see the message in the notification area and if I accept it again the message get duplicated in the app.
how I can avoid that? Is there away to remove it from the notification area once the push is accepted.
In other words, once
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
is executed, I want to remove the notification from the notification area.
Setting the badge value to 1 or some value first then set it back to 0 worked. Like the following:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Try this maybe?
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];

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.