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