简体   繁体   中英

How to detect if a photo was taken with the iPhone

I know how to access the photos on the iPhone using the APIs from PhotoKit (eg PHAsset, PhotoLibrary, ...) from objective-c.

How can I safely determine if a photo was taken with the iPhone my code is running on? Are there any properties (eg of PHAsset or EXIF) that can reliably be used for that? My app should only use photos that were actually taken using the current phone's camera.

First of all you need to get metadata of image. In case of using PHAsset you can create some extension for getting of metadata. For example:

-(void)requestMetadataWithCompletionBlock:(PHAssetMetadataBlock)completionBlock{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        PHContentEditingInputRequestOptions *editOptions = [[PHContentEditingInputRequestOptions alloc] init];
        editOptions.networkAccessAllowed = YES;
        [self requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
            CIImage *image = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
            dispatch_async(dispatch_get_main_queue(), ^{
                completionBlock(image.properties);
            });
        }];
    });
}

In the dictionary can find camera maker. For example:

      ...
      Make = Apple;
      Model = "iPod touch";
      ...

And also worth to take a look at ImageIO Framework , here you will find some default keys for metadata parsing and other useful info.

But there are no public API that tell you that the photo was taken by current iOS device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM