ioscocoa-touchassetslibrary

Find the list of photos inside a device


For a little program that i'm developing, i need to find the list of images and photos inside the device, in this case iPhone Simulator (i saved some images taken from internet). I now that in Android is present the "Cursor" inside the "android.database" API. Is there something similar in Objective C ? I found interesting this tutorial: How I get all the images from a perticular folder(iPhone)? , but in this case the user pass manually the path. In my case i don't know the path where are the images, so i need to use something that search automatically inside the paths. I also saw that for this problem, the AssetsLibrary framework can help, but i'm new on Objective C programming and i'm not sure if it is what i need.

Thanks for each help.


Solution

  • I used this framework myself and it proves to be very helpful. Using the AssetsLibrary framework, you can get the referenceURL from the info dictionary and fetch the asset. Something like this:

    NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
    
    __block NSString *fileName = nil;
    
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library assetForURL:assetURL resultBlock:^(ALAsset *asset)  
    {
        fileName = asset.defaultRepresentation.fileName;
    } 
    failureBlock:nil];