gpt4 book ai didi

ios - 如何在 swift 注册时根据该 PhoneNumber 检索 uid

转载 作者:行者123 更新时间:2023-11-29 05:20:39 31 4
gpt4 key购买 nike

我有 registerButton 和 otpButton 用于成功注册到应用程序。在点击注册按钮时,我将 otp 发送到该注册的电话号码。在 otpButton 中进行 otp 验证后,该人成功注册,我将获得 uid

现在我想检查用户在注册时是否已经注册..为此我已将 uid 保存在 otpButton 中..并在 registerButton 中检索 uid 以检查 uid 是否不为 nil 然后显示警报消息...但是一直在这里,包括新用户,我也得到最近注册的人 uid 为什么?

如何检查用户是否已经使用其电话号码注册。

将 uid 保存在 otpButton 中:

do{
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
print("the json of otppppppppp \(json)")
DispatchQueue.main.async {
if (self.otpTextField.text == String(self.otpField ?? 12)){
print("registration successfullllll...")
let mobileNum = json["mobile_number"] as! [String : Any]
self.regUid = mobileNum["id"] as? String
print("otp uid \(String(describing: self.regUid))")

DispatchQueue.main.async {
KeychainWrapper.standard.set(self.regUid!, forKey: "regUid")
}
print("the otp uid keywrap \(KeychainWrapper.standard.set(self.regUid!, forKey: "regUid"))")

let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.present(loginVC, animated: true)
}
}
}

检索uid以检查用户是否已经注册

do{
let userId: String? = KeychainWrapper.standard.string(forKey: "regUid")
print("reg userid \(userId)")
if userId != nil{
DispatchQueue.main.async {
AlertFun.ShowAlert(title: "Title", message: "user exist", in: self)
}
}
else{
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
print("the json regggggggggggis \(json)")
let phNum = json["mobile_number"] as? Int
let status = json["status"] as? String
self.otpField = json["otp"] as? Int
}
}

请帮我根据uid注册时检查用户是否存在。

最佳答案

使用手机号码代替 regUid 作为钥匙串(keychain) key

do{
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
print("the json of otppppppppp \(json)")
DispatchQueue.main.async {
if (self.otpTextField.text == String(self.otpField ?? 12)){
print("registration successfullllll...")
let mobileNum = json["mobile_number"] as! [String : Any]
self.regUid = mobileNum["id"] as? String
print("otp uid \(String(describing: self.regUid))")

DispatchQueue.main.async {
KeychainWrapper.standard.set(self.regUid!, forKey: mobileNum)
}
print("the otp uid keywrap \(KeychainWrapper.standard.set(self.regUid!, forKey: mobileNum))")

let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.present(loginVC, animated: true)
}
}
}

let mobileNumber = "" // set mobile number
do{
let userId: String? = KeychainWrapper.standard.string(forKey: mobileNumber)
print("reg userid \(userId)")
if userId != nil{
DispatchQueue.main.async {
AlertFun.ShowAlert(title: "Title", message: "user exist", in: self)
}
}
else{
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! [String: Any]
print("the json regggggggggggis \(json)")
let phNum = json["mobile_number"] as? Int
let status = json["status"] as? String
self.otpField = json["otp"] as? Int
}
}

关于ios - 如何在 swift 注册时根据该 PhoneNumber 检索 uid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58713601/

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