How can i change badge number of my iphone app increasingly with push notification? - iphone

I have an app. I build the push notification system, and i can set the badge number also when i pushed a notification, but if i want to send another push notification, i cannot increase the badge number of application. Can i do that ?

This is not possible, you have to keep track of the badge number on the server side.

Related

iOS: Notification Badge Number does not reset

I want to reset the notification badge number whenever the app is opened. This works perfectly fine calling
application.applicationIconBadgeNumber = 0
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
However, when I one ore more new notifications come in, the icon badge number again goes to 42 no matter how many notifications come in.
Does anyone know how to fix this?
You can follow one of the following for achieving this,
You can store notifications received in your database and when user opens app, you can get the count of unread notifications and update the count.
If you are targeting single users then, you can get the delivery of Push notifications using https://stackoverflow.com/a/50044201/5084797 and then when the notification is opened you can pass notification Open event to server. So the next time the server sends push notification, they can just check for the difference in Deliver and Open and send that count in badge. If user has cleared all notifications from Notification centre without opening them. In that case as soon as App opens you need to update that at server, Else you might be getting wrong count from server.

When multiple push notification selecting one disappears others from the tray

I am having the case when i am getting multiple notifications and when i select any one of them it opens up my app and does according my code.Then when i check other notifications are disappeared from the tray. Is this the usual case with notifications that opening one will remove others too or I am missing something?
I also have the question about bedge icons for multiple notifications also it is always shows 1 on the app icon. on opening of any of notification i set it to 0(zero). Does this bedge manage by server? If so how server will identify that this device is sent this many number of notifications?
As bedge are always shows 1, if i set bedge count as
int bedge = [UIApplication sharedApplication].applicationIconBadgeNumber;
bedge--;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:bedge];
It goes to negative numbers.
you're not missing anything its usual case just because by clicking on any noti your app is getting open so all were disappear because all are related to the same application that's why once you open your app from any noti other were disappears.
About APNS:
Once your app is registered to APNS you will receive the device token. That device icon your are passing to third party server and if third party want to send the notification to the device then it will contact to APNS and ask to push the notification.
About Badges:
The badges will handled by OS. That means whenever third party pushing the notifications to the device then OS is automatically increase the count.Once you open the any notification in device notification bar or lock screen it will directly navigate to the application. Because your app ID is registered to APNS and it automatically sets the count to 0.

Update push notification badge count

I am stating to implement push notifications in my app and have a question about the badge count. I would like my app to behave like email and other apps, such that every time an alert is received the badge count number increments.
Since the badge count number is part of the payload, what is the best way to have it increment?
When I send my first notification with the message and badge number, what do I do on subsequent notifications? Do I need to store all the notifications I send?
Any clarification on this would be most helpful.
Thanks for the help!
If you want to increment the number, you have to keep track of it on the server, there's no other way.
This one really depends on what the notifications are for. If its for a news app and you are pushing breaking news it'll be quite difficult to increment the badge properly. Where as if it a game app and you are pushing to tell the player its their turn it would be much easier.
Examples (Psuedo):
News App
Article Posted
1.1 Push Sent
1.2 Added to a database of pushes including who it was sent to, check
database for other pushes to the same user, sees no previous push,
BADGE = 1.
App is Opened
2.1 Badge goes back to 0, tells database to delete all pushes for that
device/user/ BADGE = 0
Article Posted
3.1 Push Sent
3.2 Added to a database of pushes including who it was sent to, check
database for other pushes to the same user, sees no previous push,
BADGE = 1.
Article Posted
4.1. Added to a database of pushes including who it was sent to, check
database for other pushes to the same user, sees previous push,
BADGE = 2.
App is Opened
5.1 Badge goes back to 0, tells database to delete the pushes for that
device/user. BADGE = 0
Game App
Player 2 Goes
Push to Player 1, check database to see if it is Player 1's turn in
any other game, BADGE = Count of games where its P1's turn.

APNS and iOS 5 Notification Center

I'm using iOS 5 and Push Notifications (with notification bar).
I have received 5 notifications that are available in the notification center. When I tap on any of them, the app launches and I am presented with the payload dictionary in application:didFinishLaunchingWithOptions. After this point, all other notifications related to the app disappear from the notification center.
I want to know if I can achieve any of the following
I can let the unread (untapped) notifications be available in the notification list (for later viewing).
I can get the payload(s) of all unread notifications in application:didFinishLaunchingWithOptions when I tap any one unread notification.
For notifications to remain in Notification Center after your app has been launched from one of them, their payload needs to include a badge number, and your app needs to refrain from setting its badge counter to 0 until it wants to clear all of its notifications from the Notification Center.
There is no way to access the notification payload of APNS messages other than the one your app was launched from. The general best practice if you need that data—particularly considering that APNS delivery is not guaranteed—is to retrieve it separately from your own web service.

Can we cancel a push notification from application on iOS5?

On iOS5, the push notification shows on the top bar and not block user. When the push notification is showing and user click our application but not the push bar, our app will launch normally. However, we want to cancel the push notification at that time. Is it possible ? Thanks a lot!
Short answer: No. There is no way you can manipulate sent notifications as far as I know.
Slightly longer answer:
Once a push request has been sent to the Apple Push Notification servers, thats it. It disappears into their system and they will then try to deliver it on a 'best effort' basis. You receive no feedback about its status or any ability to change/delete it.
The only form of feedback you can get is about which devices do not wish to receive push notifications that you tried to send to.
If you want to send delayed notifications which can be cancelled/modified at later data, either write you own solution, or use some pre-existing solution (e.g Urban Airship).