0

Hey Guys so what I am trying to do is when the user gets a notification then goes into the app or clears it in the notification settings I want to debadge the app icon

import UIKit

class TechByteSchedulingViewController:UIViewController  {

    @IBOutlet weak var datePicker: UIDatePicker!

    @IBAction func DateChosen(sender: UIButton) {
        self.sendNotification()
    }

    func sendNotification() {

        var localNotification = UILocalNotification()
        localNotification.fireDate = datePicker.date
        localNotification.repeatInterval = .CalendarUnitDay
        localNotification.alertBody = "check out your Daily Tech Byte"
        localNotification.alertAction = "Open"
        localNotification.timeZone = NSTimeZone.defaultTimeZone()
        localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
        localNotification.soundName = UILocalNotificationDefaultSoundName
        UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

}
    func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
        UIApplication.sharedApplication().applicationIconBadgeNumber = 1
        UIApplication.sharedApplication().applicationIconBadgeNumber = 0
        UIApplication.sharedApplication().cancelAllLocalNotifications()

    }
Andy Ibanez
  • 12,104
  • 9
  • 65
  • 100

2 Answers2

0

I thought it was

application.applicationIconBadgeNumber = 0

or

currentInstalltion.badge = 0

and then saving it in the background

No?

Edison
  • 11,881
  • 5
  • 42
  • 50
  • For both make sure it's in AppDelegate didFinishLaunchingWithOptions function and you saveInBackground. – Edison Aug 02 '15 at 03:42
0

Maybe try

application.applicationIconBadgeNumber = 0 

in your AppDelegate didFinishLaunchingWithOptions function

Caleb
  • 5,548
  • 3
  • 25
  • 32