请教:
目前很多流行APP可以验证码直接登陆,前提是手机号码不用注册,更不需要先行注册用户名和密码。那LeanCloud_IOS支持验证码直接登陆吗?我尝试但是报错。
报错:
2017-08-08 21:55:21.509 Rest20170806[2630:216742] [ERROR] +[AVErrorUtils errorFromJSON:] [Line 201] error: Error Domain=AVOS Cloud Error Domain Code=201 "Password is missing or empty" UserInfo={error=Password is missing or empty, NSLocalizedDescription=Password is missing or empty, code=201}
Error Domain=AVOS Cloud Error Domain Code=201 "Password is missing or empty" UserInfo={error=Password is missing or empty, NSLocalizedDescription=Password is missing or empty, code=201}
我的源码:
@IBAction func getVerificationCondBtn_clicked(_ sender: Any) {
// 判断TextFiled是否为空
if mobilePhoneTxt.text!.isEmpty {
let alert = UIAlertController(title: "请注意", message: "手机号码不能为空", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(ok)
present(alert, animated: true, completion: nil)
return
}
// 正则判断手机号码
// 注册用户数据上传云端
let user = AVUser()
user.username = mobilePhoneTxt.text!
user.mobilePhoneNumber = mobilePhoneTxt.text!
user.signUpInBackground { (success, error) in
if success {
print("用户名上传成功")
}else{
print(error ?? "用户名上传失败")
}
}
AVUser.requestLoginSmsCode(mobilePhoneTxt.text!) { (success, error) in
if success {
print("获取验证码成功")
}else{
print(error ?? "获取验证码失败")
}
}
}
@IBAction func signInBtn_clicked(_ sender: Any) {
// 判断TextField不能为空
if verificationCodeTxt.text!.isEmpty {
let alert = UIAlertController(title: "请注意", message: "验证码不能为空", preferredStyle: .alert)
let ok = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(ok)
present(alert, animated: true, completion: nil)
return
}
AVUser.logInWithMobilePhoneNumber(inBackground: mobilePhoneTxt.text!, smsCode: verificationCodeTxt.text!) { (user, error) in
print("登陆成功")
UserDefaults.standard.set(user?.username, forKey: "username")
UserDefaults.standard.synchronize()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
}
}
-
创建时间
17年8月6日
-
最后回复
17年9月28日
-
3
回复
-
3.2K
浏览
-
3
用户
-
1
链接