gpt4 book ai didi

ios - 当我从Scheme Url(Swift项目)启动应用程序时,openURL没有被调用

转载 作者:行者123 更新时间:2023-12-02 03:06:56 25 4
gpt4 key购买 nike

当我通过 myapp://param1=abc 打开应用程序时,不会调用 open url 函数。

我已经添加了函数 didFinishLaunchingWithOptionswillFinishLaunchingWithOptions 使其成为 true,正如 Apple 文档所述,但它仍然没有被调用。应用程序完美打开,但未调用函数 open url 我无法获取 param1

这是我的 AppDelegate 文件:

class AppDelegate: UIResponder, UIApplicationDelegate  {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Here doesn't come! :(
return true
}


// MARK: UISceneSession Lifecycle


func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}

知道会发生什么吗?

谢谢!

最佳答案

openUrl的签名AppDelegate中的方法已更新为,

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return true
}

您需要添加您的urlScheme在项目设置的信息选项卡下的URL类型中,即

enter image description here


对于 Swift-5 和 iOS-13:

SceneDelegate.swift文件,您需要实现以下方法来处理 urlSchemes ,即

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts)
}

关于ios - 当我从Scheme Url(Swift项目)启动应用程序时,openURL没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58748323/

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