0

我正在构建一个要求用户拥有照片的应用程序。我要做的是自动保存占位符照片,直到他们选择相机/照片库并选择一个选项。我的问题是它没有发生。我使用了 Parse 文档中的代码以及我自己选择的有效照片源代码。当没有检测到照片时,它仍然不会自动保存照片。我知道在 Parse 中查找 nil 和/或数据很复杂。问题也可能是我首先是如何建立我的 photo.image 的。如果您对如何在用户没有照片时保存我的照片有任何想法,请提供帮助。这是我的代码......

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()
            }
        }
    }
}
4

0 回答 0