【问题标题】:Application not handle <Universal Links>应用程序未处理 <通用链接>
【发布时间】:2022-08-16 19:40:44
【问题描述】:

我在使用通用链接时遇到了一些问题,我无法理解为什么我的应用无法处理通用链接。 基于 SwiftUI 的应用程序,但我使用 UIkit 进行开发

@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)\")
                }
        }
    }
}

而且这段代码也不起作用

 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
    }

在权利中,我使用:

applinks:example.com
webcredentials:example.com

我的文件的托管方式类似于 \"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\"
        ]
    }
}

为了测试我的文件,我使用: https://branch.io/resources/aasa-validator/#resultsbox 并且所有测试都通过了——

\"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:\"

我也使用https://search.developer.apple.com/appsearch-validation-tool: 苹果对我说另一个味精

Action required
Could not extract required information for application links. Learn how to implement the recommended Universal Links.
Error cannot parse app site association

但我检查语法一切都很好,我还使用了额外的网络工具,可以说到 AASA 的路由没有重定向状态码 200

我也尝试过像这样的用户修改?mode=开发者等等,但就我而言,它没有用。 我在本地模式下完成了所有测试功能。

如果我在 CMD 中使用命令(对于 .well-known & 和没有)- curl -v \'example.com/.well-known/apple-app-site-association\' 一切看起来都很好

* 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

如果我使用命令- curl -v \'https://example.com/.well-known/apple-app-site-association, 内容类型将在下一个

content-type: application/json

我在哪里有错误,我可以用什么来进行额外的调试?

  • 在当前的 AASA 格式(参见 developer.apple.com/documentation/xcode/…)中,appIDs 属性(还要注意末尾的 s)是一个数组。 (也许您将此与早期的 AASA 格式混淆了,其中确实有一个 appId 属性,但与 paths 一起而不是 components)?
  • @StephanSchlecht,感谢您的观察,您是我的英雄)),现在一切正常,API 验证存在一个新问题<Error no apps associated with URL> 但我想这是因为文件的 TeamID 错误。谢谢!

标签: ios swift swiftui ios-universal-links


【解决方案1】:

我对 AASA 文件使用了旧的语法标准,谢谢Stephen Schlecht 的观察

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 2020-03-31
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多