Issues with badge icon - ios

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?

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

How to disable application badge completely using iOS SDK

The user can disable an app from showing the badges from push notifications. How can this be done pragmatically? So far I have only found solutions where the badges are cleared when an app comes to the foreground. I am looking for a solution that would work regardless of whether the app is in the foreground, background or not launched at all.
I tried setting applicationIconBadgeNumber = 0 in appDidFinishLaunching and that didn't work.
Did you try it in applicationDidBecomeActive?. If the app is running in the background, appDidFinishLaunching will not be called

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.

Actionable push notification isn't appearing on device with iOS 8+, when user force quit app by swiping-up

I am using ONE SIGNAL for push notification
ONE SIGNAL is providing functionality of actionable push by adding "actionButtons" key including in payload.
{"actionButtons" = {"id":"1","text":"Confirm","icon":""},{"id":"2","text":"Cancel","icon":""}, "actionSelected" = "1"}
So whenever push notification will appear on device, it will appear with two buttons "Confirm" and "Cancel" and based on user's selection 'id' of the button will be stored in "actionSelected" key.
Everything above is working perfectly whenever app is in either in foreground or in background in iOS 8+
But when user force quit application (swipe-up) notification isn't appearing on device.
I have also added "Remote Notifications" in background modes, all certificate is also set perfect. I don't know what am i missing.
If anyone got any idea about this issue then kindly help.
All suggestions are welcomed. Thanks in advance.
This is a limitation related to how OneSignal handles action buttons. OneSignal uses the content-available flag as part of a technique to support custom text on action buttons and this flag is ignored in cases where the application has been force-closed.
When force quitting any iOS app, that device becomes ineligible for notifications for that specific app until that app is ran again. So if you're testing open the app, and then close it (put in background).

Application Icon badge Count is showing 2 for the first install

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.

Resources