我正在尝试为应用程序设置强密码支持。
我有一个包含正确项目的有效 JSON 文件:
{
"appLinks": {
"apps": [],
"details": [{}]
},
"webcredentials": {
"apps": [ "<TEAMID>.<BUNDLEID>", "<TEAMID>.<BUNDLEID>" ]
}
}
我在 repo 中包含了一个“.nojekyll”文件以允许 .文件夹访问 .我已经用 ( https://branch.io/resources/aasa-validator ) 验证了这一点。
我已将文件放在 /.well-known/apple-app-site-association
我已将功能添加到我的应用程序并三次检查了我的 团队 ID 和 捆绑标识符 .
我也有从我的设备中删除了该应用程序并安装了并在连接和不连接调试器的情况下运行。
我开始想 GitHub 页面 由于某种原因不支持此功能。
注意:我的 bundleID 是明确的,意思是我使用的是“app”而不是“com.company.app”
我这样想对吗?
最佳答案
不,我无法单独使用 GitHub Pages。如果你不关心为什么你可以跳过下一点。
为什么仅 GitHub Pages 是不够的
据我所知,仅 GitHub Pages 不会在 .well-known/apple-app-site-association
上提供文件。与 Content-Type: application/json
. Apple's validation tool不会通过。这个需要:
.well-known/apple-app-site-association
待送达(您可以使用 curl -v mysite.com/.well-known/apple-app-site-association
进行测试)Content-Type: application/json
标题。 -L
的情况下工作给您的curl
命令。 这是我尝试仅使用全部失败的 GitHub 页面的解决方案:
.nojekyll
到 repo 的顶级目录,以便 .well-known/apple-app-site-association
可以提供服务。尝试使用符号链接(symbolic link)重定向 apple-app-site-association
至apple-app-site-association.json
Content-Type: octet-stream
.well-known/apple-app-site-association/index.json
mydomain.com/.well-known/apple-app-site-association
重定向到 mydomain.com/.well-known/apple-app-site-association/
在返回正确的内容和正确的内容类型 header 之前。 GH Pages 解决方案之上的 Cloudflare/CDN
但是,我也在使用 Cloudflare to CDN the static pages my GitHub Pages site hosted .您可以在免费级别进行设置,如果您的页面获得任何真正的流量,可能应该这样做。您可能会选择另一个 CDN,但它需要某种支持 Apple 要求的内容类型/无重定向内容的自定义路由。在 Cloudflare 中,我可以通过他们的 Workers 的免费层免费实现这一点(除非我有大量的流量)。如果您在 GitHub Pages 站点上使用另一个 CDN,您可能可以将其余部分调整为您首选的 CDN。
在 Cloudflare 的“Workers”页面中,单击“Manage Workers”,然后单击“Create Worker”。根据需要复制/粘贴以下 JSON(它包含您的
apple-app-site-association
JSON):addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
return new Response(JSON.stringify(
// This is actually your JSON. Because this is JavaScript, you can also add in comments if you like.
{
"applinks": {
"details": [
{
"appID": "Q94XRK95RT.io.beatscratch.beatscratchFlutterRedux",
"paths": [ "/app/", "/app"]
}
]
}
}) + "\n"
, {
headers: {
"content-type": "application/json",
},
status: 200
})
}
请注意,我必须使用 here 中的 JSON 结构。 .这让上面链接的验证器显示“错误没有与 url 关联的应用程序”,这听起来很糟糕......但一切正常。我将 Worker 命名为
apple-app-site-association
但你可以随意命名它。然后您可以路由 my-site.com/.well-known/apple-app-site-association
给 worker 。
关于swift - apple-app-site-association 文件是否适用于 GitHub Pages(即 site.github.io)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60357663/