0

I have the following method which retrieves an ALAsset from the UIImagePicker after it snaps a photo. It then attempts to send this ALAsset to another one of my methods via the main thread:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSURL *imageURL = [[info valueForKey:UIImagePickerControllerReferenceURL] retain];
    __block ALAsset *result;

    [self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset)
    {
        result = [asset retain];

        dispatch_async(dispatch_get_main_queue(), ^
        {
            [self loadPhotoImageViewWithAsset:result];
            [self dismissModalViewControllerAnimated:YES];
            [imageURL release];
            [result release];
        });
    }
    failureBlock:^(NSError *error)
    {

    }];
}

When I get into the dispatch_async(dispatch_get_main_queue(), ^ block, result is showing as nil. Anyone know what I'm doing wrong here?

Ser Pounce
  • 14,196
  • 18
  • 84
  • 169

1 Answers1

2

Refer UIImagePickerController to use for a UIImageView for result is showing as nil.

Use like this:

 [self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset)
{
    result = [asset retain];
    [self loadPhotoImageViewWithAsset:result];
    [self dismissModalViewControllerAnimated:YES];
    [imageURL release];
    [result release];   
}
failureBlock:^(NSError *error)
{

}];

Change your loadPhotoImageViewWithAsset Method

-(void)loadPhotoImageViewWithAsset:(ALAsset *)asset
{
  //dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
   //dispatch_async(queue, ^{
    dispatch_async(dispatch_get_main_queue(), ^
    {
     //here code for loading image
    });
  // });
}
Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • Thanks this works when I use the UIImagePicker to select a photo from a photo library. When I try to use it with the camera it doesn't, so I guess the issue more has to do the camera. – Ser Pounce Jan 03 '13 at 06:27
  • UIImagePickerControllerReferenceURL has a url for picking a photo and capture a photo. So code remains same – Paresh Navadiya Jan 03 '13 at 06:31
  • The issue is photos taken with the imagepicker arent going to my photo library for some reason. Marked yours as correct cause you answered me question, thanks. – Ser Pounce Jan 03 '13 at 07:18