title: Application icon badge number is not changing to zero on launching the application by touching the app icon
body: <p>I am developing a local notification code . I am being able to display the badge number as per the number of notifications fired and also I am able to make all the icons to 0 when user opens the notification,But if the user launches the app the badge is not set to 0. It is only set to 0 when user opens the notification. I have read multiple answers &amp; multiple articles and couldn't find a solution . In order to register my local notification I have the following code - </p>
  
  <pre><code>func addItem(item: TodoItem)
      {
          // persist a representation of this todo item in NSUserDefaults
  
          var todoDictionary = NSUserDefaults.standardUserDefaults().dictionaryForKey(ITEMS_KEY) ?? Dictionary()// if todoItems hasn't been set in user defaults, initialize todoDictionary to an empty dictionary using nil-coalescing operator (??)
  
          todoDictionary[item.UUID] = ["deadline" : item.deadline, "title" : item.title, "UUID" : item.UUID]// store NSData representation of todo item in dictionary with UUID as key
  
          NSUserDefaults.standardUserDefaults().setObject(todoDictionary, forKey: ITEMS_KEY)
  
          let notification  = UILocalNotification()
  
          notification.alertBody = "Todo Item \"\(item.title)\" Is Overdue" // text that will be displayed in the notification
          notification.alertAction = "open" // text that is displayed after "slide to..." on the lock screen - defaults to "slide to view"
          notification.fireDate = item.deadline // todo item due date (when notification will be fired)
          notification.soundName = UILocalNotificationDefaultSoundName // play default sound
          notification.userInfo = ["title": item.title, "UUID": item.UUID] // assign a unique identifier to the notification so that we can retrieve it later
         let nextbadge = (UIApplication.sharedApplication().scheduledLocalNotifications?.count)! + 1
          notification.applicationIconBadgeNumber = nextbadge//here I provide an incremental badge number to my local notification.
          UIApplication.sharedApplication().scheduleLocalNotification(notification)
  
  
      }
  </code></pre>
  
  <p>In my appdelagate class</p>
  
  <pre><code>func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification)
      {
          NSNotificationCenter.defaultCenter().postNotificationName("ToDoListShouldtRefresh", object: self)
  
           application.applicationIconBadgeNumber = 0;
  
  
      }
  </code></pre>
  
  <p>Now in objective C I was usually doing like this to clear badges on application launch - </p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      // Override point for customization after application launch.
  
      // Handle launching from a notification
      UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
      if (locationNotification) {
          // Set icon badge number to zero
          application.applicationIconBadgeNumber = 0;
      }
  
      return YES;
  }
  </code></pre>
  
  <p>I tried something like this but with vain - </p>
  
  <pre><code> func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool
      {
  
  
          application.registerUserNotificationSettings(UIUserNotificationSettings (forTypes:[.Alert, .Badge, .Sound], categories: nil))
          if let notification:UILocalNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification
          {
  
              application.applicationIconBadgeNumber = 0
          }
          return true
  
  
  
  
  
      }
  </code></pre>
  
  <p>So how to do it now in SWIFT?</p>