从ViewController转移到PFFile的子类时,我目前遇到数据丢失的问题。传递的数据是要上传到用户配置文件的图像数据。下面是选择图像的代码:将数据传递给Singleton iOS
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Dismiss controller
[picker dismissViewControllerAnimated:YES completion:nil];
// Resize image
_focusedImage.image = image;
NSData *imageData = UIImageJPEGRepresentation(image, 0.05f);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:imageData];
[[imageUpload uploadImage] setImagePFFile:imageFile];
}
日志此视图imageFile
正确地打印出来。然而,当我通过我的单例类imageUpload uploadImage
传递数据这是数据结构的样子:
+ (imageUpload *) uploadImage
{
static imageUpload*_sharedImageUpload = nil;
_sharedImageUpload = [[self alloc] init];
_sharedImageUpload.imageData = [[NSData alloc] init];
PFUser *user = [PFUser currentUser];
_sharedImageUpload.imagePFFile = [[PFFile alloc] init];
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:_sharedImageUpload.imageData];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error)
{
[user setObject:imageFile forKey:@"image"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error)
{
NSLog(@"This should be the profile image upload");
}
else
{
NSLog(@"Something went wrong: %@", error);
}
}];
}
}];
return _sharedImageUpload;
}
当我到了这一点,该系统只是上传了一个空文件(零个字节)来分析。命名是正确的,并且它在数据库的正确位置,但是在该行的某处,文件本身的数据正在丢失。我无法弄清楚为什么。有没有人有什么建议?
@jefflovejapan我对此还比较陌生,你是什么意思? – 2014-09-26 15:44:24