gpt4 book ai didi

ios - 在我点击我的通知操作后,我的 URL 没有运行。我该怎么办?

转载 作者:行者123 更新时间:2023-11-28 08:17:41 24 4
gpt4 key购买 nike

在我的应用程序中,我希望在点击我的通知 操作时运行一个URL。问题是,当我运行 app 时,它会将我置于前台,但不会运行 URL(我将 .foreground 添加到通知 操作)。这是我的代码:

extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

if response.actionIdentifier == "call" {


if let urled = URL(string: "tel://1234567891") {
UIApplication.shared.open(urled, options: [:])
}

}


}
}

任何人的帮助都会很棒:)感谢您的任何回答!

最佳答案

对于 iOS 10:将 UserNotifications.framework 添加到您的应用程序。请检查您是否已为推送通知设置委托(delegate)。如果您已经设置了它,请尝试以下适用于 iOS 10 的方法。

import UserNotifications

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate {
}



func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void) {
print("Handle push from foreground")
// custom code to handle push while app is in the foreground
print("\(notification.request.content.userInfo)")

}


func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

print("Handle push from background or closed")

// if you set a member variable in didReceiveRemoteNotification, you will know if this is from closed or background

print("\(response.notification.request.content.userInfo)")

}

关于ios - 在我点击我的通知操作后,我的 URL 没有运行。我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42147068/

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