swift - URL 未传递给 appdelegate

标签 swift xcode appdelegate ios-universal-links

我无法使动态链接或通用链接正常工作。我的应用程序不会读取 URL。我从一个新项目开始,将 com.company.AppLoginView 的 URL 方案和以下代码添加到 AppDelegate 中。我在注释中添加了一个网址:com.company.AppLoginView://Register?User=Name。单击链接请求打开应用程序,然后该应用程序将打开。但是,似乎没有任何内容传递给应用程序,并且没有调用以下内容。我究竟做错了什么?这是一个完全空的应用程序,应该可以工作。

func application(_ app: UIApplication, open url: URL,
                 options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if let scheme = url.scheme,
        scheme.localizedCaseInsensitiveCompare("com.myApp") == .orderedSame,
        let view = url.host {

        var parameters: [String: String] = [:]
        URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.forEach {
            parameters[$0.name] = $0.value
        }

        print("View:\(view) Params:\(parameters) Scheme:\(scheme)")

//        redirect(to: view, with: parameters)
    }
    return true
}

最佳答案

这是因为目标是 iOS 13,SceneDelegate 接管了 AppDelegate 的一些功能。特别是,open:url 被 SceneDelegate scene:openURLContexts 取代。

更多信息请参见:Apple openURLContexts

我生命中的三天我不会回来!

关于swift - URL 未传递给 appdelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59733777/

相关文章:

ios - 在通知附件中使用来自 Assets.xcassets 的图像是否有比这更好的方法?

xcode - UITextField - 限制文本长度而不是字符数

iphone - 您能否要求 iPhone 3G(或更新版本)具有build设置?

xcode - 在Xcode环境中,Valgrind等效于什么?

ios - 应用程序 :openURL:sourceApplication:annotation: not called in app delegate

ios - 如何在 iOS 的一个地方处理常见错误(可以在一个地方的每个 UIViewController 中引发)?

ios - 带有标题和自定义指示器的 UIPageViewController

ios - swift 中的多个枚举值

ios - FirebaseApp.configuration() 未解析的标识符

swift - 窗口无法快速添加 subview