1

I have an app which send remote local notifications, I want to check value of my badge and display redDot accordingly. This is what I tired but doesn't seem to work,

override func viewDidLoad() {
    super.viewDidLoad()

    if UIApplication.shared.applicationIconBadgeNumber>=1{
        self.redDot.alpha=1
    }

    else{
        self.redDot.alpha=0
    }
}

when I print the value of UIApplication.shared.applicationIconBadgeNumber it prints 0 instead it of 1 because thats the value of my badge.

S.Verma
  • 199
  • 2
  • 14
  • What is the value of `UIApplication.shared.applicationIconBadgeNumber` at that point (either use `po` in debugger or a print and look in console) – Lou Franco Apr 03 '17 at 20:44
  • @LouFranco its `0` – S.Verma Apr 03 '17 at 20:54
  • What problem are you having with the code you posted? – rmaddy Apr 03 '17 at 21:04
  • @rmaddy it doesnt show my `redDot` because the badge value is being printed as `0` – S.Verma Apr 03 '17 at 21:05
  • Isn't that what you want? – rmaddy Apr 03 '17 at 21:06
  • @rmaddy , no I want my redDot to be shown when I open up my app, because my app still has the badge number but it doesnt, prints the value in `UIApplication.shared.applicationIconBadgeNumber` as `0` instead it should be `1` – S.Verma Apr 03 '17 at 21:08
  • Then update your question to reflect that issue. Your question says nothing about the fact that you seem to be getting the wrong value from `UIApplication.shared.applicationIconBadgeNumber`. – rmaddy Apr 03 '17 at 21:09
  • BTW - this is a repost of [your earlier question](http://stackoverflow.com/questions/42955562/how-do-i-check-my-applicationiconbadgenumber-value) which you accepted an answer for. Why was that answer accepted if you are asking the same question again? – rmaddy Apr 03 '17 at 21:12
  • @rmaddy it does now. – S.Verma Apr 03 '17 at 21:13
  • @rmaddy it didnt, I've unchecked the answer. – S.Verma Apr 03 '17 at 21:15

1 Answers1

0

You set up a notification to fire later with a badge number. But the notification will not automatically set the badge number.

You have to handle the notification when it fires, check the badge number value and update your app's badge number explicitly.

You check the app badge number in your other view and show/hide the red dot.

Danyl
  • 2,012
  • 3
  • 19
  • 40
  • I already have a notification which fires later. and updates my badge number. But how do I update it explicitly ? – S.Verma Apr 03 '17 at 20:49