So I had an interacitve push notification but it suddenly stopped working, this is my code:
所以我有一个交互推送通知,但它突然停止工作,这是我的代码:
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()
}
when I run the app I get the notification but I doen't recive the output: "ok" and there is no segue.
当我运行应用程序时,我收到通知但我没有收到输出:“确定”并且没有segue。
1 个解决方案
#1
0
response.actionIdentifier == "answer1" only will be true when you tap on "thank you!" option in the notification. It wont be true if you just tap the notification. please check
当你点击“谢谢你!”时,response.actionIdentifier ==“answer1”才会成立。通知中的选项。如果你只是点击通知就不会是真的。请检查
#1
0
response.actionIdentifier == "answer1" only will be true when you tap on "thank you!" option in the notification. It wont be true if you just tap the notification. please check
当你点击“谢谢你!”时,response.actionIdentifier ==“answer1”才会成立。通知中的选项。如果你只是点击通知就不会是真的。请检查