How to push notifications without badge number? - ios

I don't want to see the badge number on the app icon. but I want to keep the notifications in notification center.
How to achieve this?
The following doesn't work as it clears all the notifications in the notification center.
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
The following doesn't work as well, as it only remove the badge counter after the app is opened.
[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
I am thinking is it possible to push a negative badge number with a value of -1?

You should be able to specify what the desired badge number is when you send the push notification. From Apple's Local and Push Notification Programming Guide, if you send a number with "badge" as the key.
The number to display as the badge of the application icon. If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0.

Related

Clearing badge Icon without clearing notifications

I have to clear application badge icon while opening the application. I do clear by setting applicationBadgeIcon to 0.
=> But it clears my all notifications from notification center. I have also tried by setting applicationBadgeIcon to -1, But it also did not work for me.
Is ther Any solution?
UIApplication.shared.applicationIconBadgeNumber = 0 // Badge count was removed.
Its working fine for me in Swift 4
The thing you need to achieve will not possible if you pass the badge in payload of the push notification. If you any how achieve this behaviour then do one thing remove badge number from payload then you did not bother about to clear badge count and your push still display in notification
disadvantage:
1) user need to remove all notification one by one same like instagram
Otherwise there is no way to achieve this.

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.

Update badge icon

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.

Is it possible to remove an application icon badge yet for notifications to remain in the notification center?

My app is queuing local notifications (and can also receive APNs) and the app's icon badge is getting set as a consequence.
When the app launches I want to clear the icon badge but I want the notifications to remain in the notification center history lists. But it seems this isn't possible? Setting the badge count to 0 has the effect of removing all notifications from the notification center.
Is there any way I can leave them there so it is the user's responsibility to remove them, yet at the same time clear the app's badge?
No, unless something has recently changed, the notifications in Notification Center are tied to the applications icon badge.
This code reads like it should clear only the badge, however, it is commonly used to clear the notifications in Notification Center:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
However, when the code is used, the Notification Center notifications are cleared as well. Notification Center reads what to display based on what is displayed on the icon.
Sources:
My own experience
This previous question

Resources