简体   繁体   English

Parse.com保存图像IOS

[英]Parse.com saving image IOS

I'm trying to save an image to parse.com with the following code: 我正在尝试使用以下代码将图像保存到parse.com:

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


        PFUser *user = [PFUser currentUser];
        user[@"fullName"] = name;
        user[@"Location"] = location;
        user[@"gender"] = gender;
        user[@"email"] = email;
        user[@"ProfilePic"] = imageFile;
        [user saveInBackground];

The problem is that this doesn't seem to be saving the image file to parse as nothing is populated in my data browser. 问题是这似乎没有保存图像文件来解析,因为我的数据浏览器中没有填充任何内容。 The code here looks fine to me, but can you guys see anything wrong with it? 这里的代码看起来很好,但是你们可以看到它有什么问题吗?

The image is being downloaded from Facebook with the following code: 使用以下代码从Facebook下载图像:

NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]];
            NSData *data = [[NSData alloc] initWithContentsOfURL:pictureURL];

            UIImage *profileImage = [[UIImage alloc] initWithData:data];

Any ideas? 有任何想法吗?

Thanks 谢谢

The problem is that the [imageFile saveInBackground]; 问题是[imageFile saveInBackground]; operation has not yet been performed when you call [user saveInBackground]; 调用[user saveInBackground];时尚未执行操作[user saveInBackground];

When you call the first background save, the program just continues on. 当您调用第一个后​​台保存时,程序将继续。

Use saveInBackgroundWithBlock instead, and then do the [user saveInBackground] operation there. 改为使用saveInBackgroundWithBlock ,然后在那里执行[user saveInBackground]操作。

NSData *imageData = UIImagePNGRepresentation(profileImage);
PFFile *imageFile = [PFFile fileWithName:@"Profileimage.png" data:imageData];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        if (succeeded) {
           PFUser *user = [PFUser currentUser];
            user[@"fullName"] = name;
            user[@"Location"] = location;
            user[@"gender"] = gender;
            user[@"email"] = email;
            user[@"ProfilePic"] = imageFile;
            [user saveInBackground];
        }
    } else {
         // Handle error
    }        
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM