2017-10-18 67 views
0

所以我有一个interacitve推送通知后,工作,但它突然停止工作, 这是我的代码:UNUserNotification不更新到SWIFT 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() 
    } 

当我运行应用程序,我得到通知,但我不要收回输出:“确定”,没有赛格。

回答

0

response.actionIdentifier ==只有当您点击“thank you!”时,“answer1”才会成立。选项在通知中。如果你只是点击通知它不会是真的。请

+0

经过它,从某些原因,它甚至寿我按它 – nadavs

+0

不工作我只给: 让ANSWER1 = UNNotificationAction(标识符:“ANSWER1”,标题:“谢谢!”,选项:UNNotificationActionOptions。前景) let category = UNNotificationCategory(identifier:“myCategory”,actions:[answer1],intentIdentifiers:[],options:[])。 –