Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift URL未传递给appdelegate_Swift_Xcode_Appdelegate_Ios Universal Links - Fatal编程技术网

Swift URL未传递给appdelegate

Swift URL未传递给appdelegate,swift,xcode,appdelegate,ios-universal-links,Swift,Xcode,Appdelegate,Ios Universal Links,我无法使动态链接或通用链接正常工作。我的应用程序无法读取URL。我从一个新项目开始,在AppDelegate中添加了com.company.AppLoginView的URL方案和以下代码。我在注释中添加了一个url:com.company.AppLoginView://Register?User=Name. 单击链接请求打开应用程序,然后打开应用程序。但是,似乎没有向应用程序传递任何内容,并且没有调用下面的内容。我做错了什么?这是一个完全空的应用程序,应该可以工作 func applicatio

我无法使动态链接或通用链接正常工作。我的应用程序无法读取URL。我从一个新项目开始,在AppDelegate中添加了com.company.AppLoginView的URL方案和以下代码。我在注释中添加了一个url: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
}

您应该将ULR方案和URL标识符添加到
plist
。您可以使用以下选项:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.company.AppLoginView</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>com.company.AppLoginView</string>
        </array>
    </dict>
</array>
打开Safari并键入您的地址

com.company.AppLoginView://Register?User=Name


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

详情如下:


我生命中的三天都不会回来了

这对我有用!这里有一些细节
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    print(url)
    return true
}