ALAsset valueForProperty:ALAssetPropertyLocation u

2019-06-05 18:22发布

问题:

This might seem too easy or maybe it's just confusing for me... Or maybe I'm too tired to think rationally.

I am trying to get the location of an UIImage that has been selected by the user from the photo album using imagePickerController.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *pic = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    NSData *data = UIImageJPEGRepresentation(pic, 0.01f);
    UIImage *image1 = [UIImage imageWithData:data];
    bookmarkImage.image = image1;

    NSLog(@"new image size = %i", [data length]);

    NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
    4NSLog(@"%@",url);

    ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset){
        [myAsset valueForProperty:ALAssetPropertyLocation];
    };

    [self dismissModalViewControllerAnimated:YES];
}

Now, where I try to call the valueForProperty for ALAsset is where I have trouble. This is the error I'm getting:

Use of undeclared identifier 'ALAssetPropertyLocation'.

Please help! This is getting really frustrating... I need the location of the photo...

回答1:

It's pretty silly but I've been missing an import:

#import <AssetsLibrary/ALAsset.h>

Thanks to markus who pointed it out!