Can I detect if an imported ALAsset photo was take

2019-03-30 02:26发布

问题:

I have an imagePickerController that is used for importing photos from library into my app.

When in ALAssetsLibraryAssetForURLResultBlock, I'm trying to find out if the ALAsset I've got in the block is a photo taken as a screen-shot or is it a "genuine" photo, taken by the camera.

I've tried to go through the ALAsset's metadata dictionaries but couldn't find any flag / indication that might fit.

Anyone have any ideas?

回答1:

For screenshot, its UTI is always a "public.png" and same size as screen (be sure you have multiply [UIScreen scale] on screen bounds width and height), just need to check these 2 metadata, you can easily identify screenshot.



回答2:

Add MetaData to UIImage while saving to Photo Library. Same metadata of UIImage can be used to know if its screenshot or not.

Refer Save_Photo_to_Album_with_Metadata



回答3:

Well, I was researching and experimenting .. and the closest solution I've found is based on the fact that iPhone screenshots don't yield EXIF records (while all other generated photos do generate them).

Therefore, once a photo is selected in the picker, I'm checking if the photo's metadata consists an EXIF record and if it doesn't - I conclude that the photo was screenshot.

I found it's the "as good as it gets" solution for now, although it's not an official one.

Cheers.