Ajay
Ajay

Reputation: 1622

EXC_BAD_ACCESS on retriving NSData

In my app I am using the camera and photo library to get an UIImage...After picking the image I need to convert it to NSData and wants to pass this data to a method called addBlobToContainer:....but it gives the EXC_BAD_ACCESS.... How can I resolve this?

Here is my code for photo library...

- (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
    }
}

Upvotes: 0

Views: 959

Answers (2)

arun.s
arun.s

Reputation: 1528

Try

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

Upvotes: 1

Sulthan
Sulthan

Reputation: 130102

You are not accessing a property, you are accessing the variable behind the property. If you want the data to be automatically retained by the property, use property setters, e.g. self.imageData = ... instead of imageData = ....

Upvotes: 3

Related Questions