目前,我正在像这样触发密码重置:
static func firebasePasswordReset(email:String, responseError:@escaping (ResponseError?)->Void, completion:@escaping (
String)->Void){
Auth.auth().sendPasswordReset(withEmail: email) { (error) in
if(error != nil){
responseError(ResponseError.custom(error?.localizedDescription ?? "Unknow error occured. Please try again."))
}else{
completion(NSLocalizedString("Password reset link sent. Please check \(email).", comment: ""))
}
}
}
虽然一切正常,并且发送了相应电子邮件的链接,但用户会收到我在 Firebase 控制台中为我的网站设置的链接。
所以是https://myprojectname/reset-password.html页。
现在,对于 iOS 用户,我不希望他们去网站重置密码。我想将他们重定向到一个应用程序,并在他们的 iOS 应用程序中打开一个表单。这有可能吗?
最佳答案
1-AppDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
if let url = userActivity.webpageURL {
if url.path.range(of: "/reset-password.html") != nil {
if let passwordToken = url.getQueryItemValueForKey("token") {
let resetPasswordController= ResetPasswordController()
resetPasswordController?.passwordToken = passwordToken
self.window?.rootViewController = resetPasswordController
self.window?.makeKeyAndVisible()
}
}
}
return true
}
2 - 将您的域添加到权利中的关联域。
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:www.yourdomain.com</string>
<string>applinks:yourdomain.com</string>
</array>
3-创建 apple-app-site-association 文件
创建一个 apple-app-site-association
文件,mime 类型为 json,但不带文件扩展名。 YOUR_APP_ID 类似于 XXXXXXX.com.mycompany.projectname
并确保它必须可以通过公共(public) https://yourdomain.com/apple-app-site-association 访问与 application/json
content-type
{
"applinks": {
"apps": [],
"details": [
{
"appID": "YOUR_APP_ID",
"paths": [
"/reset-password.html*"
]
}
]
}
更新:您还必须使用 https 提供 apple-app-site-association
文件。
https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html
4-在电子邮件中,链接应包含密码 token ,如下所示,
<a href="http://yourdomain.com/reset-password.html?token=BLABLABLABLABLABLABAL">Reset Your Password</a>
5-决赛
在 ResetPasswordController
中创建密码重置表单,
方法一:当用户提交表单时,将 token
发送到您的服务器。检查 token 是否存在等。从您的 API 返回 true 或 false。
方法二:通过 API 检查 token 是否存在,然后显示您的重置表单。
关于ios - 重置密码时将用户重定向到 iOS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55983511/