從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