can we show badge without APNS? - iphone

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

Related

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.

can application find out if push notifications are enabled or disabled?

Can my application find out if push notifications were disabled through Settings on the device? I am not talking about checking with feedback.push.apple.com. I would simply like to know if the switch in the Settings was set to ON or OFF.
You can use
[[UIApplication sharedApplication] enabledRemoteNotificationTypes]
If this returns UIRemoteNotificationTypeNone which is equal to the value 0, then the application accepts no notifications. Hope this helps you.
You can find out which kind of notifications are enabled for your app using [[UIApplication sharedApplication] enabledRemoteNotificationTypes].

Badges, Update item number?

Is it possible to update the badge number without sending the application a push notification?
Such as when the application is loaded you can change the badge number?
Yes. You can use this:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:3];
This will update the value without using a push notification.

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.

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