我有一个很大的困境。我的应用程序正在运行解析sdk 1.1.12这是最新的。它会定期告诉新的注册用户名是在没有的情况下获取的。我的注册被分成三个独立的控制器,每个屏幕都有一个控制器,我将之前的注册信息传递给发生signUpInBackgroundWithBlock
的最后一个控制器。
我的猜测是我在注册前以某种方式操纵用户名?我把它转换为小写。注册确实在大部分时间都有效,这是我无法弄清楚的优势。它会抛出error.code 202,这是用户名,但我保证在发生错误时不会使用它。
它仍然会注册用户并将其成功存储在数据库中。当用户在警报上点击时,我会显示它或者将它们带入应用程序,或者他们终止应用程序并重新打开它。当他们重新打开应用程序时,它会将它们带入主屏幕。
这是我的代码:
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()
}