How do I access a photo inside the photo album

1

I would like to know how I access a photo saved inside the photo album of the device. I used UIImagePickerController but I do not need to open the photo gallery and select the photo. I would like that through the code I send the name of the image I need and return it. Is there a function to achieve this?

    
asked by Juan David Gil 10.06.2016 в 20:32
source

1 answer

1

You could try using Photo Framework, I'll leave the code in objective-c, I hope someone can swift it

-(void)getAllPhotosFromCamera
{
    imageArray=[[NSArray alloc] init];
    mutableArray =[[NSMutableArray alloc]init];

    PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
    requestOptions.resizeMode   = PHImageRequestOptionsResizeModeExact;
    requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
    requestOptions.synchronous = true;
    PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];

    NSLog(@"%d",(int)result.count);

    PHImageManager *manager = [PHImageManager defaultManager];
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];

    // assets contiene los objetos PHAsset.

    __block UIImage *ima;
    for (PHAsset *asset in result) {
        // Do something with the asset

        [manager requestImageForAsset:asset
            targetSize:PHImageManagerMaximumSize
                contentMode:PHImageContentModeDefault
                    options:requestOptions
        resultHandler:^void(UIImage *image, NSDictionary *info) {
            ima = image;

            [images addObject:ima];
        }];


    }

    imageArray = [images copy];   
}
    
answered by 11.06.2016 в 18:24