【问题标题】:Apple-app-site-association file won't downloadApple-app-site-association 文件不会下载
【发布时间】:2016-03-13 23:31:30
【问题描述】:

我已将我的 apple-app-site-association 文件上传到我的 HTTPS Web 服务器的根目录之后,我已在 xcode 中添加了我的关联域。我已按照苹果通用链接教程进行操作。

[SWC] ### 拒绝重定向到'https://examplecustomdomain.com/apple-app-site-association/'(原'https://examplecustomdomain.com/apple-app-site-association')

我检查了我的设备日志并看到了类似上述的错误

【问题讨论】:

    标签: ios ios-universal-links


    【解决方案1】:

    我遇到了一个非常相似的错误:

    [SWC] ### Denying redirect to 'https://www.<domain>/apple-app-site-association' (original 'https://<domain>/apple-app-site-association')
    

    引用 Apple 的文档:

    • 文件必须托管在具有有效证书的 https:// 网站上(例如,Safari 在查看该网站时不得发出证书警告)。

    • 文件不得使用任何重定向。

    • 该文件的 MIME 类型必须为 application/pkcs7-mime。

    我的猜测是-对于我们俩来说--文件都可以获得,但它是在重定向之后。即使在同一个域下,操作系统也不会遵循该重定向;而且,显然,在日志上抱怨它。

    运行curl -i https://&lt;domain&gt;/apple-app-site-association,您可能会看到HTTP/1.1 301 Moved Permanently,以及Location: https://www.&lt;domain&gt;/apple-app-site-association(或类似名称)。

    【讨论】:

      【解决方案2】:

      最近尝试实现通用链接功能时遇到了同样的问题。 fbeeper 给出了很好的回应,帮助我验证确实发生了重定向。

      但是,它并没有帮助我确定如何解决重定向问题。因此,对于像我这样使用基于 Ruby on Rails 的后端的人来说,这里有一个示例,说明如何以满足 Apple 的所有要求的方式提供令人讨厌的 apple-app-site-association 文件:

      • apple_app_site_association json 文件放在public 文件夹中
      • 在您的 config/routes.rb 文件中,添加如下行:

      get '/apple-app-site-association' =&gt; 'home#apple_app_site_association'

      • 然后在相关的控制器文件(本例中为 home_controller)中,定义你的方法:

        def apple_app_site_association association_json = File.read(Rails.public_path + "apple-app-site-association") render :json => association_json, :content_type => "application/pkcs7-mime" end

      【讨论】:

        【解决方案3】:

        它只适用于 https 服务器。

        步骤:

        1) 在rails应用程序的公共目录下创建一个类似apple_app_site_association的文件,没有任何扩展名,内容如下

        {
            "applinks": {
                "apps": [],
                "details": [
                    {
                        "appID": "<TEAM_DEVELOPER_ID>.<BUNDLE_IDENTIFIER>",
                        "paths": [ "*" ]
                    }
                ]
            }
        }
        

        2) 路由.rb

        get '/apple-app-site-association', to: 'pages#apple_app_site_association'
        

        3) pages_controller.rb

        def apple_app_site_association 
           association_json = File.read(Rails.public_path + "apple_app_site_association")
           render :json => association_json, :content_type => "application/json"
        end
        

        例如你检查

        http://18.216.158.101/apple-app-site-association

        为了测试,你可以在 heroku 上创建一个应用程序。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-08-28
          • 1970-01-01
          • 1970-01-01
          • 2016-01-06
          • 1970-01-01
          • 1970-01-01
          • 2017-02-16
          • 1970-01-01
          相关资源
          最近更新 更多