2013-03-16 55 views
0

在我的應用程序中,我使用相機和照片庫來獲取UIImage ...挑選圖像後,我需要將其轉換爲NSData,並希望將此數據傳遞給名爲addBlobToContainer的方法:.. ..但它給了EXC_BAD_ACCESS .... 我該如何解決這個問題?EXC_BAD_ACCESS在檢索NSData

這裏是我的照片庫中的代碼...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    image.image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; 
    imageData = [NSData dataWithData:UIImageJPEGRepresentation(image.image,1)]; 
    guid = [Guid randomGuid]; 
    NSLog(@"%@", guid.description); 
    GUID = guid.description; 
    NSLog(@"GUID===%@",GUID); 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    NSLog(@"STRIMAGEDATA===%@",imageData); 

    if ([imageData length] != 0) 
    { 
     NSLog(@"%@",imageData); 
     [client addBlobToContainer:newcontainer blobName:GUID contentData:imageData contentType:@"application/octet-stream" withBlock:^(NSError *error) 
     { 
      if (error) 
      { 
      NSLog(@"%@",[error localizedDescription]); 
      } 
       else 
       { 
       NSLog(@"blob inserted suuccessfully…"); 
       imageURL = [serviceURL stringByAppendingString:[NSString stringWithFormat:@"%@.jpg",GUID]]; 
       NSLog(@"IMAGEURL=%@",imageURL); 
       } 
      }];-->EXC_BAD_ACCESS 
    } 
} 
+0

向我們展示'imageData'的聲明。它是「強」還是「弱」? – Sulthan 2013-03-16 12:19:16

+0

也是serviceURL和GUID的聲明。 – 2013-03-16 12:20:14

+0

不要給你的標識符名稱,如「圖像」。使用適當的枚舉UIImagePickerControllerEditedImage不是你定義的字符串(這可能是問題?) – 7usam 2013-03-16 12:22:48

回答

3

您沒有訪問屬性,您要訪問的屬性後面的變量。如果您希望數據自動由該屬性保留,請使用屬性設置器,例如self.imageData = ...而不是imageData = ...

1

嘗試

self.imageData = UIImageJPEGRepresentation(image.image,1);