Ios 非-Swift时解析用户名出错
我有一个相当大的两难选择。我的应用程序正在最新的parse sdk 1.1.12上运行。它会定期告诉新注册用户,用户名已被使用,但实际情况并非如此。我的注册分为三个独立的控制器,每个屏幕都有一个控制器,我将以前的注册信息传递到出现Ios 非-Swift时解析用户名出错,ios,swift,parse-platform,Ios,Swift,Parse Platform,我有一个相当大的两难选择。我的应用程序正在最新的parse sdk 1.1.12上运行。它会定期告诉新注册用户,用户名已被使用,但实际情况并非如此。我的注册分为三个独立的控制器,每个屏幕都有一个控制器,我将以前的注册信息传递到出现signUpInBackgroundWithBlock的最后一个控制器 我猜我在注册前是在操纵用户名吧?我把它转换成小写。大多数时候,注册确实有效,这是一个我无法理解的边缘案例。它抛出error.code 202,这是用户名获取的,但我保证在错误发生时不会获取它 它仍然
signUpInBackgroundWithBlock
的最后一个控制器
我猜我在注册前是在操纵用户名吧?我把它转换成小写。大多数时候,注册确实有效,这是一个我无法理解的边缘案例。它抛出error.code 202,这是用户名获取的,但我保证在错误发生时不会获取它
它仍然注册用户,并成功地存储在数据库中。当用户在警报中点击OK时,我显示它要么将他们带入应用程序,要么他们终止应用程序并重新打开。当他们重新打开应用程序时,就会进入主屏幕
以下是我的片段:
func parseSignUpUser() {
// creating the new user
self.showHudWithTitle("Signing Up...")
user.username = self.email!.lowercaseString
user.password = self.password
user.email = self.email!
user["fullName"] = self.firstName!+" " + self.lastName!
user["University"] = self.universityName
user["Sex"] = self.gender
user["Age"] = NSNumber.init(long: ageNow!)
// If user seleceted a profile image save it
if (self.profileImageVw.image != nil) {
let profileData = UIImageJPEGRepresentation(self.profileImageVw.image!, 0.5)
let profileFile = PFFile(name: "profilePicture.png", data: profileData!)
let thumbnailData = self.profileImageVw.image ? .resizeImage()
let thumbnailFile = PFFile(name: "thumbnailPicture.png", data: thumbnailData!)
user["profilePicture"] = profileFile
user["thumbnailImage"] = thumbnailFile
let myImageName = "profile.png"
let imagePath = DBAccessManager.sharedInstance.fileInDocumentsDirectory(myImageName)
self.saveImage(UIImage(data: thumbnailData!) !, path: imagePath)
}
user.signUpInBackgroundWithBlock {
(succeeded: Bool, signUpError: NSError ? ) -> Void in
if signUpError == nil {
//successfully sign up the user
} else {
//If email has been used for another account kPFErrorUserEmailTaken
if (signUpError!.code == 202) {
appDelegate.log.info("Error Code 202: Email Taken")
let alertController = UIAlertController(title: "Sign Up Failed", message: "Sorry! Email has been taken! ", preferredStyle: .Alert)
appDelegate.log.error("Error on 202")
let OKAction = UIAlertAction(title: "OK", style: .Default) {
(action) in
// ...
}
alertController.addAction(OKAction)
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
self.presentViewController(alertController, animated: true) {
// ...
}
}
else if (signUpError!.code == 203) {
//If email has been used for another account kPFErrorUserEmailTaken ...
} else if (self.profileImageVw.image == nil) {
// If the user does not have an image show alert
...
} else {
// all other cases show alert
...
}
}
} // end of parseSignUpUser()
}
你确定你的应用在注册时只调用parseSignUpUser()一次吗?如果这个方法被调用了两次,那么其中一个会在另一个之前竞争,第二个会说用户名已经存在。是的,它只被调用了一次,问题是它偶尔会出现,当它说用户名不存在时,大多数人都注册了。