Parse.com保存图像IOS

Khl*_*don 3 objective-c ios parse-platform

我正在尝试使用以下代码将图像保存到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];
Run Code Online (Sandbox Code Playgroud)

问题是这似乎没有保存图像文件来解析,因为我的数据浏览器中没有填充任何内容.这里的代码看起来很好,但是你们可以看到它有什么问题吗?

使用以下代码从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];
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

谢谢

Mar*_*dal 11

问题是[imageFile saveInBackground];当您打电话时尚未执行操作[user saveInBackground];

当您调用第一个后​​台保存时,程序将继续.

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
    }        
}];
Run Code Online (Sandbox Code Playgroud)