所以我有一个交互式推送通知,但它突然停止工作,这是我的代码:
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()
}当我运行应用程序时,我收到了通知,但没有收到输出:"ok“,并且没有segue。
发布于 2017-10-19 00:57:16
只有当你点击“response.actionIdentifier ==”时,"answer1“才是真的。通知中的选项。如果你只是点击通知,那就不是真的。请查收
https://stackoverflow.com/questions/46812413
复制相似问题