gpt4 book ai didi

ios - 更新到 swift 4 后 UNUserNotification 不起作用

转载 作者:行者123 更新时间:2023-11-30 12:04:37 25 4
gpt4 key购买 nike

所以我有一个交互式推送通知,但它突然停止工作,这是我的代码:

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”并且没有继续。

最佳答案

response.actionIdentifier == "answer1"仅当您点击“谢谢!”时才为 true通知中的选项。如果您只是点击通知,情况就不会如此。请检查

关于ios - 更新到 swift 4 后 UNUserNotification 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46812413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com