默认检索的表是Bmob的自带表_User,可以通过BmobObject(className: "表名")
账号密码登录,账号可以为用户名、手机号或者邮箱
BmobUser.loginInbackground(withAccount: account.text, andPassword: pwd.text) { (user, error) in
//登录成功后的操作
}
Bmob请求发送验证码
-
@param number 手机号
-
@param templateStr 模板名(任意皆可)
BmobSMS.requestCodeInBackground(withPhoneNumber: self.account.text, andTemplate: "test", resultBlock: { (msgId, error) in
//各种代码
})
验证短信
BmobSMS.verifySMSCodeInBackground(withPhoneNumber: account.text, andSMSCode: verifyCode.text) { (isSuccessful, error) in
if isSuccessful {
print("success")
let vc = xxViewController() //跳转页面
self.present(vc!, animated: true, completion: nil)
}
}
上传文件,用照片做例子,以下是打开相册后调用的方法
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let query = BmobQuery(className: "_User")
query?.getObjectInBackground(withId: BmobUser.current().objectId, block: { (object, error) in
if ((object) != nil) {
let ig = UIImagePNGRepresentation(image)
//上传到Bmob的文件中,文件名是123456.png,可随意修改
let file = BmobFile(fileName: "123456.png", withFileData: ig)
file?.save(inBackground: { (isSuccessful, error) in
if (isSuccessful) {
print((file?.url)!)
}
})
object?.setObject(file, forKey: "Avatar")
object?.saveInBackground(resultBlock: { (isSuccessful, error) in
if isSuccessful {
print("success")
}
})
}
else {
print("error")
}
})
self.dismiss(animated: true, completion: { () -> Void in
self.headImage.image = image //显示照片
})
}
网友评论