2017-10-18 3 views
0

donc j'ai eu une notification push interacitve mais il a soudainement cessé de fonctionner, voici mon code:UNUserNotification ne fonctionne pas après la mise à jour rapide 4

func pushNotification(){ 
    let content = UNMutableNotificationContent() 
    let answer1 = UNNotificationAction(identifier: "answer1", title: "thank you!", options: UNNotificationActionOptions.foreground) 

    let category = UNNotificationCategory(identifier: "myCategory", actions: [answer1, answer2], intentIdentifiers: [], options: []) 
    UNUserNotificationCenter.current().setNotificationCategories([category]) 
    content.sound = UNNotificationSound.default() 
    //Created notification 
    content.body = "how are you?" 
    content.categoryIdentifier = "myCategory" 
    content.badge = 1 
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false) 
    let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger) 
    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) 
} 



@objc(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:) func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) 
    { 

     if response.actionIdentifier == "answer1" 
     { 
      print("ok") 
      performSegue(withIdentifier: "FastResult", sender: self) 
     } 

     completionHandler() 
    } 

quand je lance l'application que je reçois la notification mais je ne pas recevoir la sortie: "ok" et il n'y a pas de segue.

Répondre

0

response.actionIdentifier == "answer1" sera seulement vrai lorsque vous appuyez sur "merci!" option dans la notification. Ce ne sera pas le cas si vous appuyez simplement sur la notification. s'il vous plaît vérifier

+0

vérifié, d'une certaine raison, il ne fonctionne même quand je le presse – nadavs

+0

Je ne donne pas: laisser answer1 = UNNotificationAction (identifiant: « answer1 », titre: « merci! », les options: UNNotificationActionOptions. au premier plan) let category = UNNotificationCategory (identificateur: "myCategory", actions: [answer1], intentionIdentifiers: [], options: []). –