Application Icon badge Count is showing 2 for the first install - ios

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.

Related

iOS App Icon Badge disappears after app goes to background

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

Issues with badge icon

I have a strange issue with badges.
Here is the code which sets badge count getted from backend
UIApplication.shared.applicationIconBadgeNumber = badge
so the issue is, when app connected to debugger its successfully changes the badge, but when I disable it from debugger and run it, the badge icon doesnt change, and its only on one iphone, other ones work fine with same code.
So can you help to understand the problem with this one?

Increment in iOS Push Notification incrementing all time, even Zero is set?

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.

How to hide the apple push notification badge count, as soon as app installed?

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;
//.....
}

How can I set badge count of iOS app from its today extension?

I'm looking for a way to update the badge count of iOS app icon from its iOS8 today extension. Today extension has a button and by touching that button, user can increase or decrease badge count of iOS app. Can anyone help me with this?
PS: I need to update the badge count without reopening the app even when the app is terminated.
As you already have created group, you can keep a file in the group folder and add a filewatcher in extension, update the file from app, and filewatcher will catch the change, and your work is done.

Resources