【问题标题】:Apple-app-site-association file won't downloadApple-app-site-association 文件不会下载
【发布时间】:2016-03-13 23:31:30
【问题描述】:
【问题讨论】:
标签:
ios
ios-universal-links
【解决方案1】:
我遇到了一个非常相似的错误:
[SWC] ### Denying redirect to 'https://www.<domain>/apple-app-site-association' (original 'https://<domain>/apple-app-site-association')
引用 Apple 的文档:
我的猜测是-对于我们俩来说--文件都可以获得,但它是在重定向之后。即使在同一个域下,操作系统也不会遵循该重定向;而且,显然,在日志上抱怨它。
运行curl -i https://<domain>/apple-app-site-association,您可能会看到HTTP/1.1 301 Moved Permanently,以及Location: https://www.<domain>/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' => '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 上创建一个应用程序。