gpt4 book ai didi

ios - 推送通知中的自定义按钮操作

转载 作者:行者123 更新时间:2023-11-29 05:39:25 27 4
gpt4 key购买 nike

我在推送通知中添加了两个按钮,并且能够在应用程序处于前台或后台模式时执行此类操作。我对此很满意,但当应用程序被终止时我无法执行操作。

   func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
let userInfo = response.notification.request.content.userInfo
print(userInfo)
guard let apsdata = userInfo[AnyHashable("data")] as? [String:AnyObject] else {
return
}

switch response.actionIdentifier {
case "ACCEPT_ACTION":
if let pushdatadict = apsdata["body"] as? [String:AnyObject] {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "AcceptOfNotification"), object: nil, userInfo: pushdatadict)
}
print("request accepted buddy")
case "DECLINE_ACTION":
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RejectOfNotification"), object: nil)
print("request decline buddy")
default:
break
}

最佳答案

func didReceive(_ 响应:UNNotificationResponse,completionHandler 完成:@escaping (UNNotificationContentExtensionResponseOption) -> Void) {

            switch response.actionIdentifier {
case "ACCEPT_ACTION":
APIToAcceptTheUserRequest()
DispatchQueue.main.async(execute: {
if let url = URL(string: "open://Home") {
self.extensionContext?.open(url) { success in
print(success)
}
}
})
print("request accepted buddy")

case "DECLINE_ACTION":
APIToRejectTheUserRequest()

default:
break
}
completion(UNNotificationContentExtensionResponseOption.dismissAndForwardAction)

}

关于ios - 推送通知中的自定义按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56698655/

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