0

I'm building an app that requires the user to have a photo. What I'm trying to do is autosave the placeholder photo until they choose the camera/photo gallery and choose a pick. My problem is that it's not happening. I've used the code from the Parse documentation as well as from my own choose photo source code that works. It still will not automatically save the photo when no photo is detected. I know finding nil and/or data in Parse is complicated. The problem may also be how I'm establishing my photo.image in the first place. If you have ideas on how to get my photo to save when a user doesn't have one please help. Here is my code.....

if let userPicture = PFUser.currentUser()?["userPhoto"] as? PFFile {
    userPicture.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
        if !(error != nil)
        {
            if imageData != nil
            {
                self.profileIMG.image = UIImage(data: imageData!)
            }
            else
            {
                let image = UIImage(named: "blueplaceholder2.png")
                let imageData = UIImageJPEGRepresentation(image!, 0.25)!
                let imageFile = PFFile(name:"image.png", data:imageData)
                let user = PFUser.currentUser()
                user!.setObject(imageFile, forKey: "userPhoto")
                user!.saveInBackground()
            }
        }
    }
}
Charles Jr
  • 8,333
  • 15
  • 53
  • 74
  • So initially you are querying the user for an image... However there is a special query type, `PFQuery.userQuery`, that you should use to query the user class. Not that this is causing your problem, but it just may be. – MikeG Jan 27 '16 at 00:32
  • I'm getting this message after I login a new user......Error]: invalid session token (Code: 209, Version: 1.7.5) . Is there anyway around this?? – Charles Jr Jan 28 '16 at 03:05
  • Perhaps open up a new question for that and include the code for your login/signup methods – MikeG Jan 28 '16 at 03:09

0 Answers0