【问题标题】:Parse.com saving image IOSParse.com保存图像IOS
【发布时间】:2014-04-03 15:19:16
【问题描述】:

我正在尝试使用以下代码将图像保存到 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];

有什么想法吗?

谢谢

【问题讨论】:

    标签: ios objective-c parse-platform


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多