SwiftUI混合UIKit应用无法处理Universal Links问题求助
iOS混合SwiftUI/UIKit应用无法处理Universal Links排查
我开发的一款混合SwiftUI与UIKit的iOS应用,无法处理Universal Links,相关代码均未生效。
SwiftUI入口代码(未生效)
@main struct iOSApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { WrapperUIVC_Hello().edgesIgnoringSafeArea(.all) .onOpenURL { url in // don't work print("Universal link \(url)") } } } }
AppDelegate相关代码(未生效)
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL, let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { print("Universal Link trouble") return false } for queryItem in components.queryItems ?? [] { print("Universal link components \(queryItem)") } return true }
已完成的配置
Entitlements配置
applinks:example.com webcredentials:example.com
托管的apple-app-site-association文件
路径:example.com/.well-known/apple-app-site-association 和 example.com/apple-app-site-association
文件内容:
{ "applinks": { "apps": [], "details": [ { "appID": "U678YHJU89.com.example", "components": [ { "#": "society/lettings" }, { "#": "society/lettings/*" }, { "#": "society/acquisitions" }, { "#": "society/acquisitions/*" } ] } ] }, "webcredentials": { "apps": [ "U678YHJU89.com.example" ] } }
测试结果
- 第三方验证工具测试通过:
"This domain validates, JSON format is valid, and the Bundle and Apple App Prefixes match (if provided).
Below you’ll find a list of tests that were run and a copy of your apple-app-site-association file:"
- 苹果官方App Search验证工具报错:
Action required
Could not extract required information for application links. Learn how to implement the recommended Universal Links.
Error cannot parse app site association
- HTTP请求测试:
- HTTP请求会301重定向到HTTPS:
* Connected to example.com (myip) port 80 (#0) > GET /.well-known/apple-app-site-association HTTP/1.1 > Host: example.com > User-Agent: curl/7.79.1 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 301 Moved Permanently < Server: nginx/1.18.0 < Date: Tue, 09 Aug 2022 17:24:18 GMT < Content-Type: text/html < Content-Length: 169 < Connection: keep-alive < Location: https://example.com/.well-known/apple-app-site-association < <html> <head><title>301 Moved Permanently</title></head> <body> <center><h1>301 Moved Permanently</h1></center> <hr><center>nginx/1.18.0</center> </body> </html> * Connection #0 to host example.com left intact - HTTPS请求返回的Content-Type为:
content-type: application/json
- HTTP请求会301重定向到HTTPS:
疑问
我已检查JSON语法无误,确认AASA文件在HTTPS路径下无重定向、返回状态码200,尝试过添加?mode=developer等修改但无效,所有测试均在本地模式下进行。请问我哪里存在错误,还有哪些调试方法可以使用?
内容的提问来源于stack exchange,提问作者Ice
相关产品推荐
相关产品推荐

