iosuiimagealassetslibrary

Loading/Retrieving an image from Photos Library based on metadata in iOS


I have an iOS application that I am working where I am capturing an image, and then storing it in my Photos Album. I realize that I am able to write custom metadata for this image when I store it using the following:

writeImageDataToSavedPhotosAlbum:metadata:completionBlock:

My question is, is it possible for me to somehow retrieve this same image later on, using this metadata as my search criteria (if for example I store this same metadata in CoreData, and use it later in a query)? An example of possible metadata I am planning on using is either a date and time stamp, and/or geolocation. Is retrieval of images possible using metadata and not knowing the exact file name?


Solution

  • If you already have a Core Data store, save all of the metadata and the asset URL (for the default representation). Then you can do all of your querying locally and access the assets only when required (though you should check they haven't been deleted before showing results).

    When you have done your search to get the asset URL you can get the image using assetForURL:resultBlock:failureBlock: from the ALAssetsLibrary.