I am setting 0 application icon badge number, as below as opening app.
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
but as server sends increment while app is in background of killed state, it never again starts with ZERO.
Say, if it is 2, than will be 3, than will be 4 on every push. If I open App and set it ZERO, and go back, it shows nothing on iCON, but as server sends, it starts from 5.
In short, it keeps existing counter.
How can I fix this issue. I have iOS 10.1, and Xcode 8.1
Thanks.
The payload that comes from server already has a badge number that will be setted, so no matter what it was previously. Only badge number that you get in payload matters.
What you need to do is add some custom logic to the place where you call [UIApplication sharedApplication].applicationIconBadgeNumber = 0; so you can reset server badge count each time you activate the app.
Related
We are developing an application containing a chat.
Our issue only happens after a fresh app install:
Install the app
Login of an existing user who has some unread chat messages, so I set the app badge to N (number of unread messages) when I download from the server the chat information (using setApplicationIconBadgeNumber).
Send the app to background (tapping the HOME button)
As the app goes to background, the app icon badge is set to N (the number of unread messages), but after a second the N badge disappears!
There are several strange behaviors in this:
After the N badge disappeared, if I 'move' the app icon by long tapping and moving it on the screen the badge reappears to stay.
If after launcing the app the first time and before going to background, the app receives a push notification, the badge doesn't disappear.
After the first app run, on all the following runs this effect doesn't happen and the N badge remains.
When the app is killed during the first run, the app badge doesn't appear at all (even if by our logs we set the value through setApplicationIconBadgeNumber).
We logged all the app setApplicationIconBadgeNumber instances and there is never a set to '0' after being set to N for the app icon badge.
We also checked the system console and there are only system logs reporting the correct set of the app icon badge: [com.mychatapp.app] Setting badge number to N
In my case, it was because I was using Airship's SDK and instead of using their code for updating the badge count, I was using the iOS native code and that caused a glitch, especially right after a reinstallation and grant the push perms again
My client has two options for how they want the badge count to operate:
Ideal would have been to that the badge count matches the number of notifications in the notification centre associated with the app client-side, but iOS doesn't give you that count, and I can't track it via just counting because they might clear notifications/notifications might expire.
Alternatively, they would like the app not to clear the notifications when you reset the badge count to 0. It appears that iOS also does not give you that option, as resetting the badge count to 0 automatically clears the notification centre for your app.
I'm working in react-native, but could drop into native code to resolve this if necessary.
I have integrated push notification into iOS app. My problem is once I install the app, and reinstall it in another time, even before I login through the app my app icon shows the badge count. I dont want to show it if the user has logged out. So when user click on the logout I set the badge count as 0. But when I install it again, even before I log into it my app shows the notification badge count as a different number.
How can I avoide this? Please help me.
Thanks
You need to add more logic to your badge updates. In the app delegate, when the app is launched and / or you receive a notification you should check the user login status and update the badge number. If the user is not logged in then you can always simply set to zero.
set badge 0 inside logout button action
-(void)logout{
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
//.....
}
I am using UILocalNotifications in my application, When i am launching the app for the first time badge count on app icon shows 2. Same thing is happening when i installed the app with IPA file.if i opened the application once and enters in to background then no badge count is showing.
I am using the following code to set the badge count to 0 for the first time.
if ( ! [[NSUserDefaults standardUserDefaults]boolForKey:#"FIRSTRUNCOMPLETE"] ) {
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:#"FIRSTRUNCOMPLETE"];
What should i do to make the badge count as 0 for the first installation.
This usually happens when you deleted the app (while it was showing some badge number), and re-installed it again. It should not show after the app has completed running for the first time after install. If you still see the badge after setting applicationIconBadgeNumber, then the problem could be somewhere else.
So I've got a UILocalNotification setup to change the Icon badge.
[myNote setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
So it works fine if I don't change the badge number after I set it. If the badge shows 2, lets say, when I set the notification, it changes to 3 when the notification goes off. But lets say that I change it from 2 to 5 within the app before the notification fires, it still changes it to 3 when it does fire.
I need it to be able to add 1 to the current badge number, not the number that the badge showed when I first scheduled the notification. Ex: If it's 2 when I schedule the notification, then change it to 5 in the app, the notification should change it 6 when it does fire.
Is there a way to do it? I'm beginning to hate UILocalNotification.
Thanks guys!
Unfortunately, there is no such API. You can, however, discard all your previous notifications and reschedule them with the updated badge number. But I agree with you, local notifications and badge numbers are bound to reach a brick wall and annoy you.