问题描述
为了在 Apple 平台上使用自动填充密码,我正在此 website 中测试 Apple App Site Association (AASA) Validator
。
我已在 Public/.well-kNown/apple-app-site-association 文件中添加了所需的 json,以便在我的 iOS 应用程序上使用自动填充密码。
此测试的结果返回此错误:
Your file's 'content-type' header was not found or was not recognized
。
有人遇到过这个问题吗?似乎 AASA 文件没有下载到我的设备中。
请注意,在 iOS 14 上,AASA 文件将通过 Apple 的 CDN 传送,这与当前下载 AASA 文件的方式不同。
解决方法
我遇到了同样的问题,按照 imike 的回答并做了一些研究,这是解决方案。
- 创建自定义中间件
struct UniversalLinksMiddleware: Middleware {
func respond(to request: Request,chainingTo next: Responder) -> EventLoopFuture<Response> {
guard request.url.string == "/.well-known/apple-app-site-association" else {
return next.respond(to: request)
}
return next.respond(to: request).map { response in
response.headers.add(name: "content-type",value: "application/json")
return response
}
}
}
- 在
config.swift
文件中添加此中间件。请注意添加中间件的顺序,必须在FileMIddleware
之前添加。因为离开应用程序的响应以相反的顺序通过中间件。
app.middleware.use(UniversalLinksMiddleware())
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))