ios - Parse.com 保存图像 IOS

标签 ios objective-c 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];

问题是这似乎没有保存要解析的图像文件,因为我的数据浏览器中没有填充任何内容。这里的代码对我来说看起来不错,但是你们能看出它有什么问题吗?

图像是使用以下代码从 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];

有什么想法吗?

谢谢

最佳答案

问题是调用[user saveInBackground];[imageFile 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
    }        
}];

关于ios - Parse.com 保存图像 IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22820842/

相关文章:

ios - 在 Parse 上存储信息

ios - CoreAnimation : To resize a instance of CALayer, 哪个性能更好?变换还是界限?

ios - 将项目升级到 Xcode 8

iphone - 我的自定义 View Controller 委托(delegate)不工作

objective-c - 带有自定义 segues 的自动布局

ios - UICollectionViewCell 位置加倍

ios - 在 iOS 中如何像 Java 中的 System.currentTimeMillis() 那样获取当前时间?

ios - 注册 Darwin 通知并通过回调发送事件详细信息 - 代号一

javascript - 在云代码中测试用户名是否在 Parse 的 User 类中

ios - 使用 Parse 查询和更新投票?