0

Ich versuche, lokalen Vordergrund Benachrichtigungen mit der folgenden iOS-Bibliothek zu implementieren: https://github.com/kunass2/BSForegroundNotificationWie plane ich lokale Benachrichtigungen in iOS, die pausiert oder entfernt werden können?

Ich mag, dass die Benachrichtigung ausgelöst, nachdem der Countdown 0 erreicht, aber Probleme habe eine gute Möglichkeit, Pause implementieren zu finden und starten Sie Tasten auf dem Timer das pausiert auch die Benachrichtigung oder richtet eine neue ein.

Dies ist meine aktuelle Implementierung, die wegen fehlschlägt, wenn ich Neustart drücken beabsichtigt Abfeuern der neuen Benachrichtigung für den Reset-Timer zu aktivieren, die alte Meldung auch gebrannt wird:

func setupLocalNotifications() { // called whenever current timer countdown reaches 0 
let notification = BSForegroundNotification(userInfo: userInfoForCategory("ONE_BUTTON")) 
    notification.timeToDismissNotification = NSTimeInterval(10) 
    // Delay 10 seconds 
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(self.timeRemaining * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {() -> Void in 
     if self.willDisplayForegroundNotification { 
      notification.presentNotification() 
     } 
    } 
    notification.delegate = self 
} 

@IBAction func startPauseButtonPressed(sender: AnyObject) { 
     if self.counting { 
      self.timer?.invalidate() 
      UIApplication.sharedApplication().cancelAllLocalNotifications() 
      self.willDisplayForegroundNotification = false 
      self.counting = false 
      startPauseButton.setTitle("Resume", forState: .Normal) 
      startPauseButton.setImage(UIImage(named: "Play.png"), forState: .Normal) 
     } 
     else { 
      setupLocalNotifications() 
      self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(NewFocusViewController.countdown), userInfo: nil, repeats: true) 
      self.willDisplayForegroundNotification = true 
      self.counting = true 
      startPauseButton.setTitle("Pause", forState: .Normal)  
     } 
} 

@IBAction func restartButtonPressed(sender: AnyObject) { 
    self.timer?.invalidate() 
    UIApplication.sharedApplication().cancelAllLocalNotifications() 
    self.timeRemaining = Double(self.timeMax) 
    self.counting = false 
    self.willDisplayForegroundNotification = false 
    self.updateTimer() 
    self.startPauseButton.setTitle("Start", forState: .Normal) 
} 

Antwort

0

ich dieses Problem behoben durch die Umsetzung die Methode didReceiveLocalNotification() in App Delegate, um die Benachrichtigung im Vordergrund anzuzeigen.

Verwandte Themen