作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 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/
我是一名优秀的程序员,十分优秀!