Clear Application's badge Number - iphone

I have made local notification in iphone app. And set icon badge number.
All works good. But if i have two notification in tray and user clicks on clear button than notification deletes from tray.
But the badge number of icon remains same.
I want to set the badge number to zero.
Thanks.

use this in application didfinshlaunchingwithoptions
application.applicationIconBadgeNumber = 0;

For Swift3, you can clear badge number in your application didFinishLaunchingWithOptions with this line :
UIApplication.shared.applicationIconBadgeNumber = 0
You can used this line in anywhere in code if you want too.

What you want to achieve is only possible using the Server Notifications. You can not set badge number locally without opening the application. As you won't have any control when user clears the tray. There's no way you can set the badge count at that moment.

Related

How to show dot badge instead of counter badge in app launcher icon?

I am using flutter_local_notifications: ^9.7.0 to show notification and that's really nice package, using that package I am available to get badge with icon "1" when notification pops up. What I would like to ask.. instead of showing "1" badge, I would like to show dot badge. Is there a way to do that using flutter_local_notifications or any other package ?
Notification Badges are Platform's entity & unfortunately, you can not do anything to change it.
As mentioned in Android docs
These dots appear by default in launcher apps that support them and there's nothing your app needs to do.

Local Notification to be shown as Alert Type

I am using local notifications in my application. I want to show local notifications as Alert Type on iphone devices while it is displaying as Banner Type. I have also set the alert type of local notification that is not contains the null value. Please Suggest.
You can't change the way a Notification is presented by code, iOS handles the displaying the notifications.
Only the user can set the way a notification is presented from the settings app.

alert/notification in locked screen

I want to do a simple alert as per given time from the application,alert is also show if phone is locked. and when press ok then go to application view(if phone is locked). if we can not navigate to the application programmatically, then i can do manually do the screen unlock. but when i do the unlock the application should open. so is there any way to do like this?
Yes i know the i can do it with local notification but my question is : when i click "View detail" or any other button + my phone is locked - so can i go to my app.
I think your are looking for Local Notifications see About Local Notifications and Push Notifications

Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually? [duplicate]

I'm setting my applicationIconBadgeNumber using this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:theIntToDisplay];
The problem is that when I delete the app from an iPad and reinstall it, the app icon still shows the previous badge number. Is this default iOS behavior or can we reset it?
I found one similar question on at Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually?, but it didn't answer my question.
This is an expected behavior, the badge number remains for a short period after uninstall e.g for the case of an immediate re-install.
Of course you can nullify badge number after every launching the application in application:didFinishLaunchingWithOptions: method but I think it is not the case because you want badge number not to be shown right after you install app and not yet launch it. In such a case just wait after removing the application and the badge numbers cache will be cleared by iOS and then install the app again. Unfortunately without jailbreaking the device there is no way to manage badge numbers behavior manually
In your app delegate under:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
Insert:
application.applicationIconBadgeNumber = 0;

iPhone notification icon

On my program icon i want to show how many show a number, like on the AppStore program icon, where it shows how many updates are available. How can i implement this on my own program icon?
Your application can add a badge icon number by calling:
[UIApplication sharedApplication].applicationIconBadgeNumber = 1; // any NSInteger
This is available in iPhone 2.0, but in 3.0 the application doesn't have to be running to update the number using the push notification service (requires server in the cloud).