问题
I have regButton and verifyOtpButtn for successful registration. in regButton i am giving phone number, for new user i will get otp, after entering otp i need to click verifyOtpButtn, here after successful registration i will get Uid in verifyOtpButtn...
now how to check the user is new user or already registred user while registration. I am able to register new user but unable to check the user is already registered or not.. please help me in the below code.
here i am saving sucessful registered uid in verifyOtpButtn:
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")
}
let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.present(loginVC, animated: true)
}
}
}
if i try to check the user is already registred or not while clicking regButton, all the time i am getting only recently registered user id, even for new user also it says user exist why? i am getting correct message from backend but i am unable to check it in frontend?
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
}
}
Please help me, how to check if user is already registered or not while registration.
来源:https://stackoverflow.com/questions/58746910/how-to-check-condition-if-user-already-registered-with-phone-number-or-new-user