gpt4 book ai didi

ios - 重置密码时将用户重定向到 iOS 应用程序

转载 作者:搜寻专家 更新时间:2023-11-01 06:52:49 25 4
gpt4 key购买 nike

目前,我正在像这样触发密码重置:

  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>

enter image description here

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- 在电子邮件中,链接应包含密码标记,类似这样,

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com