remove push notification once it is accepted by user - iphone

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];

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.

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.

can we show badge without APNS?

I want to simulate push notification without using apple's push notification server, so I want to know can I show badge also if yes which API or Objective-C code I have use to show badge?
Yes. Use [[UIApplication sharedApplication] setApplicationIconBadgeNumber:<n>]. See the documentation.
We can use [[UIApplication sharedApplication] setApplicationIconBadgeNumber:<n>] to show the badge with out APNS.
If we want to reset the previous badge while application is restarted ,we can use this
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

How can I update the [[UIApplication sharedApplication] scheduledLocalNotifications] array?

This may be more of a question regarding how to update arrays in general, but I have an app that is utilizing UILocalNotifications, and I want to allow users to select the notifications they have set, and edit them.
So what could I do to update an object at an index?
[[[UIApplication sharedApplication] scheduledLocalNotifications] ??];
Thanks for any help!
Once you get the UILocalNotification object, you can "reschedule" it by canceling the old notification with:
[[UIApplication sharedApplication] cancelLocalNotification:aNotification];
and scheduling a new one:
[[UIApplication sharedApplication] scheduleLocalNotification:aNotification];
You can not able to edit an already existing notification.
But you can able to cancel it by using cancelLocalNotification: and create a fresh notification.

setApplicationIconBadgeNumber when called multiple times does not update the badge

I am working on an application where in I have to update the badge shown in the app icon multiple times. However, what I have noted is that, the setApplicationIconBadgeNumber api just works once during the lifetime of the app. I have tries using the UILocalNotification, and it works then but, I dont want to follow that route. Have you guys faced a similar problem. If yes, any pointers?
Regards
Nitin
This is a bug in iOS. It's still present today in 6.0.1, where I just fixed it with a work-around:
// Clear app badge number. Work-around for bug in iOS.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
Might the problem be from where you are calling it?
Wrong:
// This is only called once during application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
Correct:
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}