How to remove Single Remote notification in iphone - 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.

Related

Local Notification (repeat) fired after new install of app

in my app I am using local notifications and often they have a repeat interval set.
The problem is, when the user deletes the app and reinstalls it, the repeat notifications start firing again.
Is there a fix for this problem? Will the following suggestion from another user work? :
you can use [[UIApplication sharedApplication] cancelAllLocalNotifications]; only at first launch, so that "old" notification will be cancelled....(I haven't tried that)
Thanks a lot!
you can use [[UIApplication sharedApplication]
cancelAllLocalNotifications]; only at first launch, so that "old"
notification will be cancelled...
This is not your solution. This will cancel all your already scheduled notification every time when your didFinishLaunching method will called. So before applying above solution there should be one more check. Store a value in NSUserDefauls for checking that you are installing application again after deleting.
if(![[NSUserDefaults standardUserDefaults]objectForKey:#"Notification"]){
[[UIApplication sharedApplication] cancelAllLocalNotifications]
[[NSUserDefaults standardUserDefaults]setBool:Yes ForKey:#"Notification"];
}
This will prevent from canceling all notifications every time.

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

Remove a local notification from iPhone by Date

there is the possibility of a LocalNotification on the iPhone to load on a date?
My problem is that I create an event for the notification but i release the object after creation.
Or can I just create a new Object with the same data to delete my Notification?
sorry for my english...
scheduledLocalNotifications will give you the list of all scheduled notifications and use
- (void)cancelLocalNotification:(UILocalNotification *)notification
or you can cancel them all using:
[[UIApplication sharedApplication] cancelAllLocalNotifications];

sample code for canceling the local notification in iphone

Sample code for canceling the local notification.
I am having a application which sets a local notification and now i want to cancel one of the local notification set the by the application can someone provide the sample code for the same
Cancel all local notifications with this code:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
(you actually just need the middle line.
Cancel one local notification with this line of code:
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
where theNotification is a UILocalNotification object, so in order to cancel a specific notification you need to hold on to it's UILocalNotification.
You can find more stuff in apple's documentation: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html