iOS 8 Photos framework. Access photo metadata

后端 未结 6 1194
臣服心动
臣服心动 2020-12-07 11:33

I\'m looking at replacing ALAssetsLibrary with Photos framework in my app.

I can retrieve photos, collections, and asset sources just fine (even write t

6条回答
  •  Happy的楠姐
    2020-12-07 12:23

    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.

提交回复
热议问题