Parse.com保存图像IOS
我正尝试使用以下代码将图像保存到parse.com:Parse.com保存图像IOS,ios,objective-c,parse-platform,Ios,Objective C,Parse Platform,我正尝试使用以下代码将图像保存到parse.com: NSData *imageData = UIImagePNGRepresentation(profileImage); PFFile *imageFile = [PFFile fileWithName:@"Profileimage.png" data:imageData]; [imageFile saveInBackground]; PFUser *user = [PFUse
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];
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];
问题是,这似乎并没有保存要解析的图像文件,因为我的数据浏览器中没有填充任何内容。这里的代码对我来说很好,但你们能看到它有什么问题吗
该图像正在从Facebook下载,代码如下:
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];
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];
有什么想法吗
谢谢问题在于
[imageFile saveInBackground]调用[user saveInBackground]时,尚未执行code>操作代码>
当您调用第一次后台保存时,程序将继续运行
改用saveinbackgroundithblock
,然后在那里执行[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
}
}];