在signUpInBackgroundWithBlock期间将configuration文件图像上传到parse.com时遇到问题

我正在使用下面的代码注册一个用户名,密码和个人资料图片。

func createUserwithAllFields() { let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6) //let profileImageData = UIImageJPEGRepresentation(profileImg, 0.6) let profileImageFile = PFFile(data: profileImageData) if tv_username.text != "" && tv_password.text != "" { var user = PFUser() user.username = tv_username.text user.password = tv_password.text user["profileImage"] = profileImageFile user.signUpInBackgroundWithBlock({ (success, error) -> Void in if error == nil { //if SignUp is successful let installation = PFInstallation.currentInstallation() installation["user"] = user installation.saveInBackgroundWithBlock(nil) //self.showChatOverview() self.goToMainScreen() } else { } }) }else{ } } 

当我看着parse.com上的User class时,有一个文件被上传(见下面的截图) 在这里输入图像说明

虽然有一个文件,当我点击它并下载它,我打开它find一个空白(即白色)图像。

profileAvatar是ViewController中的UIImageView ,它指向一个有效的图像,因为我可以看到,当我运行应用程序。

这是我看到的空白图像: 在这里输入图像说明

在parsing你需要先保存用户,保存图像后,我修改你的代码来完成:

 func createUserwithAllFields() { let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6) let profileImageFile = PFFile(data: profileImageData) if tv_username.text != "" && tv_password.text != "" { var user = PFUser() user.username = tv_username.text user.password = tv_password.text user.signUpInBackgroundWithBlock({ (success, error) -> Void in if error == nil { /println("SignUp is successful") user["profileImage"] = profileImageFile user.signUpInBackgroundWithBlock({ (success, error) -> Void in if error == nil { println("Image Saved") } else { println("Fail to Save Image") } )} } else { println("Fail to Sign up") } }) }else{ println("Invalid username and password") } }