Objective c 从parse.com下载图片

Objective c 从parse.com下载图片,objective-c,image,parse-platform,imageview,Objective C,Image,Parse Platform,Imageview,我想从parse.com下载一个图像文件,并在ImageView“myImageView”中显示它。我为此创建了一个名为“Image”的类和一个列“profilImage”作为文件列。我用那个代码试过了,但还是不行 PFQuery *query = [PFQuery queryWithClassName:@"Image"]; [query getObjectInBackgroundWithId:@"Y7ahcw9ZNR" block:^(PFObject *imageObject, NSErro

我想从parse.com下载一个图像文件,并在ImageView“myImageView”中显示它。我为此创建了一个名为“Image”的类和一个列“profilImage”作为文件列。我用那个代码试过了,但还是不行

PFQuery *query = [PFQuery queryWithClassName:@"Image"];
[query getObjectInBackgroundWithId:@"Y7ahcw9ZNR" block:^(PFObject *imageObject, NSError *error) {

PFFile *theImage = [imageObject objectForKey:@"profilImage"];
NSData *imageData = [theImage getData];
UIImage *yourImage = [UIImage imageWithData:imageData];

NSLog(@"%@", yourImage);

[myImageView setImage:yourImage];

}];

我做错了什么?

尝试一下使用PFFile函数。getData是同步的,可能会阻塞UI线程,具体取决于它的使用方式

[theImage getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    myImageView.image = [UIImage imageWithData:data];
}];

从解析中保存和检索profilePic

-目标-c

保存图像以解析currentuser

NSData *imageData = UIImagePNGRepresentation(image);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
[imageFile saveInBackground];

PFUser *user = [PFUser currentUser];
[user setObject:imageFile forKey:@"profilePic"];
[user saveInBackground];
PFUser *cUser = [PFUser currentUser];
PFFile *pictureFile = [cUser objectForKey:@"profilePic"];

        [pictureFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            if (!error){
                [_profileImage setImage:[UIImage imageWithData:data]];
            }
            else {
               // there is no profile picture.

            }
        }];
  var currentUser = PFUser.currentUser()
  let imageData = UIImagePNGRepresentation(image)
  let imageFile = PFFile(name:"image.png", data:imageData)
  currentUser["profilePic"] = imageFile
  currentUser.saveInBackground()
var currentUser = PFUser.currentUser()
let userImageFile  = currentUser!["profilePic"] as? PFFile
userImageFile!.getDataInBackgroundWithBlock {
            (imageData: NSData?, error: NSError?) -> Void in
         if error == nil {
            if let imageData = imageData {
               self.profileImage.image = UIImage(data:imageData)

                }
            }
       else
            {
                let errorString = error!.userInfo?["error"] as? String
                //there is no profile pic                
            }
        }
从Parse Currentuser检索图像

NSData *imageData = UIImagePNGRepresentation(image);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
[imageFile saveInBackground];

PFUser *user = [PFUser currentUser];
[user setObject:imageFile forKey:@"profilePic"];
[user saveInBackground];
PFUser *cUser = [PFUser currentUser];
PFFile *pictureFile = [cUser objectForKey:@"profilePic"];

        [pictureFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            if (!error){
                [_profileImage setImage:[UIImage imageWithData:data]];
            }
            else {
               // there is no profile picture.

            }
        }];
  var currentUser = PFUser.currentUser()
  let imageData = UIImagePNGRepresentation(image)
  let imageFile = PFFile(name:"image.png", data:imageData)
  currentUser["profilePic"] = imageFile
  currentUser.saveInBackground()
var currentUser = PFUser.currentUser()
let userImageFile  = currentUser!["profilePic"] as? PFFile
userImageFile!.getDataInBackgroundWithBlock {
            (imageData: NSData?, error: NSError?) -> Void in
         if error == nil {
            if let imageData = imageData {
               self.profileImage.image = UIImage(data:imageData)

                }
            }
       else
            {
                let errorString = error!.userInfo?["error"] as? String
                //there is no profile pic                
            }
        }
-迅捷的

保存图像以解析currentuser

NSData *imageData = UIImagePNGRepresentation(image);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
[imageFile saveInBackground];

PFUser *user = [PFUser currentUser];
[user setObject:imageFile forKey:@"profilePic"];
[user saveInBackground];
PFUser *cUser = [PFUser currentUser];
PFFile *pictureFile = [cUser objectForKey:@"profilePic"];

        [pictureFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            if (!error){
                [_profileImage setImage:[UIImage imageWithData:data]];
            }
            else {
               // there is no profile picture.

            }
        }];
  var currentUser = PFUser.currentUser()
  let imageData = UIImagePNGRepresentation(image)
  let imageFile = PFFile(name:"image.png", data:imageData)
  currentUser["profilePic"] = imageFile
  currentUser.saveInBackground()
var currentUser = PFUser.currentUser()
let userImageFile  = currentUser!["profilePic"] as? PFFile
userImageFile!.getDataInBackgroundWithBlock {
            (imageData: NSData?, error: NSError?) -> Void in
         if error == nil {
            if let imageData = imageData {
               self.profileImage.image = UIImage(data:imageData)

                }
            }
       else
            {
                let errorString = error!.userInfo?["error"] as? String
                //there is no profile pic                
            }
        }
从Parse Currentuser检索图像

NSData *imageData = UIImagePNGRepresentation(image);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
[imageFile saveInBackground];

PFUser *user = [PFUser currentUser];
[user setObject:imageFile forKey:@"profilePic"];
[user saveInBackground];
PFUser *cUser = [PFUser currentUser];
PFFile *pictureFile = [cUser objectForKey:@"profilePic"];

        [pictureFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            if (!error){
                [_profileImage setImage:[UIImage imageWithData:data]];
            }
            else {
               // there is no profile picture.

            }
        }];
  var currentUser = PFUser.currentUser()
  let imageData = UIImagePNGRepresentation(image)
  let imageFile = PFFile(name:"image.png", data:imageData)
  currentUser["profilePic"] = imageFile
  currentUser.saveInBackground()
var currentUser = PFUser.currentUser()
let userImageFile  = currentUser!["profilePic"] as? PFFile
userImageFile!.getDataInBackgroundWithBlock {
            (imageData: NSData?, error: NSError?) -> Void in
         if error == nil {
            if let imageData = imageData {
               self.profileImage.image = UIImage(data:imageData)

                }
            }
       else
            {
                let errorString = error!.userInfo?["error"] as? String
                //there is no profile pic                
            }
        }
根据您的问题

PFQuery *query = [PFQuery queryWithClassName:@"Image"];
[query getObjectInBackgroundWithId:@"Y7ahcw9ZNR"
                         block:^(PFObject *textdu, NSError *error) {

     if (!error) {
          PFFile *imageFile = [textdu objectForKey:@"profilImage"];
          [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
              if (!error) {
                  UIImage *image = [UIImage imageWithData:data];
              }
          }];
     }
 }];