Question

Okay so I have my ImagePicker all setup and the ALAssetLibrary setup to get the Picture and Title (if it exists for existing pictures or generic text for a new picture) but now I'm trying to figure out if there's a way I can access this information outside of the block call from the assetForURL method. So here's my code just so I can show what's happening (this is in the viewDidLoad method of a screen that is displayed after a picture selection is made)

__block NSString *documentName;
    __block UIImage *docImage;
    NSURL *resourceURL = [imageInfo  objectForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
    {
        ALAssetRepresentation *imageRep = [asset defaultRepresentation];
        //Get Image
        CGImageRef iref = [imageRep fullResolutionImage];
        //If image is null then it's a new picture from Camera
        if (iref == NULL) {
            docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
            documentName = @"New Picture";
        }
        else {
            docImage = [UIImage imageWithCGImage:iref];
            documentName = [imageRep filename];
        }
    };
    // get the asset library and fetch the asset based on the ref url (pass in block above)
    ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
    [imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];

Now I want to be able to use the two variables (documentName and docImage) elsewhere in this ViewController (for example if someone wants to change the name of the document before they save it I want to be able to revert back to the default name) but I can't seem to figure out what I need to do so these variables can be used later. Don't know if this makes much sense or not, so if I need to clarify anything else let me know.

Was it helpful?

Solution

Okay so I figured out that the problem wasn't with the code but with my logic on how I was using it. I was trying to do this on the Modal View that was presented after an image was selected instead of just doing this in the ImagePicker screen and then calling the Modal window inside of the result block code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top