2015-08-02 1 views
0

Hey Guys donc ce que je suis en train de faire est lorsque l'utilisateur reçoit une notification passe ensuite dans l'application ou efface dans les paramètres de notification Je veux debadge l'icône de l'applicationicône app unbadging (rapide) des problèmes d'exécution

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() 

    } 

Répondre

0

Je pensais qu'il était

application.applicationIconBadgeNumber = 0 

ou

currentInstalltion.badge = 0 

puis l'enregistrer en arrière-plan

Non?

+0

Pour les deux assurez-vous qu'il est en fonction AppDelegate didFinishLaunchingWithOptions et vous saveInBackground. – tymac

0

Peut-être essayer

application.applicationIconBadgeNumber = 0 

dans votre fonction didFinishLaunchingWithOptions de AppDelegate