Clear Application's badge Number
Asked Answered
Z

3

13

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.

Zymogenic answered 31/7, 2013 at 10:49 Comment(5)
you can set icon badge number while app launch.Thermos
Yes. But i want to reset it when user clears tray.Is it possible?Zymogenic
[UIApplication sharedApplication].applicationIconBadgeNumber=0;Articular
no you can not set icon badge number without opening application.Thermos
actually you can. but you need to used push notification [developer.apple.com/library/content/documentation/…Cruet
J
3

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.

Jerad answered 31/7, 2013 at 10:55 Comment(3)
Is it possible to get that tray has any notification when app launches?Zymogenic
@Impossible no there's no way. You have no control at that moment.Jerad
so, to be clear Rushi, what you're saying is that what @Impossible wants to do is Impossible?Lily
B
10

use this in application didfinshlaunchingwithoptions

        application.applicationIconBadgeNumber = 0;
Briar answered 31/7, 2013 at 11:21 Comment(1)
I want to clear badge number when you clicks on clear button on trayZymogenic
A
4

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.

Appearance answered 21/2, 2017 at 16:13 Comment(1)
I am having the problem that even if I delete the badge number with the above code, if a new message coming the badge number is not starting from 1, but having x+1 where x was the previous number of messages. What can be the issue here?Amery
J
3

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.

Jerad answered 31/7, 2013 at 10:55 Comment(3)
Is it possible to get that tray has any notification when app launches?Zymogenic
@Impossible no there's no way. You have no control at that moment.Jerad
so, to be clear Rushi, what you're saying is that what @Impossible wants to do is Impossible?Lily

© 2022 - 2024 — McMap. All rights reserved.