首先:
我有这个简单的PFUser结构:
_User: {...,picture:PFFile, picture_thumb:PFFile,...}
当我为用户保存图片时,我这样做:
在
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){
...
let imageData = UIImageJPEGRepresentation(imageResized!, 0.7)
let picture = PFFile(name: "picture.jpg", data: imageData!)
self.viewUploadPicture.hidden = false
self.progressUploadPicture.progress = 0.0
PFUser.currentUser()?.setObject(picture, forKey: "picture")
picture.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in
self.progressUploadPicture.progress = 0.0
self.viewUploadPicture.hidden = true
if error != nil {
print("upload image error: \(error?.userInfo)")
return
}
print("upload image OK")
self.imgUser.image = imageResized
self.imageUpdated = true
PFUser.currentUser()?.saveInBackground()
}, progressBlock: { (perc:Int32) -> Void in
print("uploading image \(Float(perc)/100)%")
self.viewUploadPicture.hidden = false
self.progressUploadPicture.progress = Float(perc)/100
self.lblUploadPicturePerc.text = "\(Float(perc))%"
})
}
其中 imageResized 是图像......好吧,自我解释;),以及用于UX的其他控件
好吧,我的问题是,如果我在登录后删除并重新启动我的测试设备上的应用程序,当我运行AccountDetail视图控制器时,我会显示我存储的用户当然但这就是我拥有的< / p>typealias UserFoundHandler = (PFUser) -> Void
func checkParseUser(userHandler:UserFoundHandler) {
guard let user:PFUser = PFUser.currentUser() else {
return
}
user.fetchInBackgroundWithBlock({ (remoteUser:PFObject?, error:NSError?) -> Void in
guard let user:PFUser = PFUser.currentUser() else {
self.presentParseLoginSignUp()
return
}
userHandler(user)
})
}
并调用第一个 中代码下方的函数,如果 未执行,因为图片类型是NSData而不是PFFile,如pticure_thumb字段正确保存后关于Image模块的解析教程。
麻烦是为什么!我想念一下吗?func fromUserToComponents(user:PFUser){
print("fromUserToComponents \(user)")
if let imageFile: PFFile = user.objectForKey("picture") as? PFFile {
... code to set fill an UIImageView
}
}
打印结果为:
fromUserToComponents <PFUser: 0x165c77b0, objectId: D8VGNQOJzu, localId: (null)> {
nickname = "Attilio Patania";
picture = <ffd8ffe0 00104a46 49460001 01000048 00480000 ffe1004c 45786966 00004d4d 002a0000 00080002 01120003
....
00d7b7fe cd5f38d3 2933ffd9>;
"picture_thumb" = "<PFFile: 0x165ab480>";
}