I am using the code below to sign up a user with username, password, and a profile picture. WHen the profile picture is a JPG
it works but NOT when the format is 'PNG`. WHen I upload a png image, the image is blank.
I think JPG
is working because I am using this function UIImageJPEGRepresentation
.
What should I be using for PNG?
Background: This thread
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{
}
}
Use the function
UIImagePNGRepresentation
insteadUIImageJPEGRepresentation
that should fix it!I hope that helps you!