Update badge icon - ios

i try to update badge icon, every time when when the app (in background)receive a push notification.
i used that in "didReceiveRemoteNotification" and "didFinishLaunchingWithOptions"
[UIApplication sharedApplication].applicationIconBadgeNumber++;
If the app is in foreground and receive few push notifications, when the app come back in backgorund the icon's badge is updated with the number of push notifications received.
But if the app is in background the icon's badge is allways 1 like in payload even the app receive many notifications.
Do you have some ideas? Thanks in advance

The push notifications that are sent to your device should have the badge numeric value which will be et automatically when push is received.
The server should somehow handle the number of your unread notifications and it sends you the correct display number in this field.

Related

Will silent notitifcation be displayed like normal notifications even if didReceiveRemoteNotifications is not called by iOS

Right now, my iOS app receives normal (non-silent) push notifications.
iOS device displays notifications as expected.
Now, I want to convert normal notifications to silent by adding "content-available=1" along with all other user visible keys.
To be able to perform bg tasks on notification trigger
My understanding is iOS may not always call didReceiveRemoteNotifications for silent notifications.
My question is would silent notifications will get displayed by iOS (if it contains user visible keys) even if iOS decides not to call didReceiveRemoteNotifications
My expectation is silent notifications should work as is like normal notifications with an advantage of didReceiveRemoteNotifications getting called as and when possible (Best Effort)
I don't want to lose normal notification behavior by switching to silent notifications.
As per this link
For a silent notification, take care to ensure there is no alert,
sound, or badge payload in the aps dictionary. If you don’t follow
this guidance, the incorrectly-configured notification might be
throttled and not delivered to the app in the background, and instead
of being silent is displayed to the user
So if the keys alert, sound and badge are added then that notification will be displayed like a normal push notification.

Is it possible to update badge number on app icon without openining app on push notification in iOS?

iOS 8 or 9
When I get push notification in my iOS app I want to update the badge number (count in red) shown on the app icon without opening the app.
Currently it gets updated only and only once the app is opened.
Is that possible?
You need to set a value for the badge key in your push notification payload. Payload Notification
The payload contains information about how you want to notify the user, such as using an alert, badge or sound. It can also contain custom data that you define.
To remove the badge, set the value of this property to 0.

Push Notification Changing Badge of AppIcon

I am working on an app that can receive Push-Notifications.
When a notification is received, I need to change the number of the icon's badge and increment it.
Those notifications are stored in a UITableView in my app.
When a row is pressed, this means that the notification has been read so I want to decrement the badge.
I am new to push notifications and badges and I really couldn't find any efficient way to do it
any solutions ?
Thank you.
You can't automatically increment a badge from a notification. Your notification payload must contain the badge property that will be set to the exact value you want for your badge.
To set the badge value from within your app, you can use:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:someInteger];
If you want to increment the badge by one every time you receive a notification, you need to keep track of your user's badge server-side.
For example, if you send 3 notifications to an user, you will have a badge column in your database for this user with 3 as a value. If the user opens his app and taps one of the notifications, your app will have to set the badge icon to 2 and send a request to your server to decrease the database value to 2.
TL;DR: There is no such thing as a badge:+1 or badge:autoincrement in a notification's payload. You have to keep track of the badge's value server-side.

iOS 7 - didReceiveRemoteNotification: not triggering on background

I know that this question is tipical but I'm missing something and I don't kwon what is.
I have a simple application, in iOS 7. Using Xcode 6. I'm developing in objective-c.
I want to receive push notifications and update my app icon badge to (1) but I can't trigger the didReceiveRemoteNotification method when the app is in background so I can't set the badge number. This is not my first app with push notifications and badges but I can't do it...
My code:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
NSLog(#"RECEIVING NOTIFICATION");
When i'm on the app the badge is correctly setted and the log is printed, but if I'm in background mode the method is not triggered.
My payload APNS
{"aps":{"alert":"New push","sound":"default"}}
I want to set the badge manualy to 1. I don't need it on de payload.
Any suggestions?
Thanks
The remote notification will set the badge automatically according to the number of "badge" in aps.
For example:
{"aps":{"alert":"New push","sound":"default","badge":1}}
A bit late, but it might help someone else.
You can trigger - application:didReceiveRemoteNotification: when your app is in background by following this two steps:
Set Required background modes to App downloads content in response to push notifications in your Info.plist file
Add "content-available": 1 to your notification payload.
This will call - application:didReceiveRemoteNotification: and allow you to handle notifications in background (i.e, refresh the content of your app, etc...).
Hope this helps!

how to get all notifications when app is in background?

I can get the notification by calling didReceiveRemoteNotification , but if the App is running in background and there are 5 notifications, how to get all notifications when App become active?
Unfortunately, there is no way to do this. The data from a notification can only be pushed by clicking the individual notification. More info here: iOS Push Notification - How to get the notification data when you click on the app icon instead of notification

Resources