I'm looking at replacing ALAssetsLibrary
with Photos
framework in my app.
I can retrieve photos, collections, and asset sources just fine (even write them back out), but don't see anywhere to access the metadata of the photos (the dictionaries such as {Exif}, {TIFF}, {GPS}, etc...).
ALAssetsLibrary
has a way. UIImagePickerController
has a way. Photos
must have a way too.
I see that PHAsset
has a location
property which will do for the GPS dictionary, but I'm looking to access all of the metadata which include faces, orientation, exposure, ISO, and tons more.
Currently apple is at beta 2. Perhaps there are more APIs to come ?
UPDATE
There is no official way to do this using only Photos APIs.
However you can read the metadata after you download the image data. There are a couple of methods to do this using either PHImageManager
or PHContentEditingInput
.
The PHContentEditingInput
method required less code and doesn't require you to import ImageIO
. I've wrapped it up in a PHAsset category.
If you request a content editing input, you can get the full image as a CIImage
, and CIImage
has a property titled properties
which is a dictionary containing the image metadata.
Sample Swift Code:
let options = PHContentEditingInputRequestOptions()
options.networkAccessAllowed = true //download asset metadata from iCloud if needed
asset.requestContentEditingInputWithOptions(options) { (contentEditingInput: PHContentEditingInput?, _) -> Void in
let fullImage = CIImage(contentsOfURL: contentEditingInput!.fullSizeImageURL)
print(fullImage.properties)
}
Sample Objective-C Code:
PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init];
options.networkAccessAllowed = YES; //download asset metadata from iCloud if needed
[asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
CIImage *fullImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
NSLog(@"%@", fullImage.properties.description);
}];
You'll get the desired {Exif}, {TIFF}, {GPS}, etc dictionaries.