0

I am trying to get the creation date for the pictures stored in the photo library using PHPhotoLibrary. The code works fine for all pictures except for a couple of PNG files that were created as screenshots on the phone by clicking the home and power button. When I iterate through the PHFetchResult and load the CIImage, the PNG files do not contain the TIFF dictionary which contains the creation date for all the other JPG files. I have searched stackoverflow extensively and found similar issues but have not found a solution yet. I have tried loading the files in different ways and have also set the compress PNG files settings to NO in the Build Settings. When I iterate through the PHAssets called pic in PHFetchResult, the PNG image properties return a dictionary with only five elements and no TIFF dictionary. The JPG files all return a much larger dictionary including the TIFF dictionary where I can find the creation date. Here is my current code which returns an empty pictiff dictionary for the PNG files:

                    [imagemanager requestImageDataForAsset:pic options:ro resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {

                    CIImage *ciimage = [CIImage imageWithData:imageData];
                    NSMutableDictionary *exif = [NSMutableDictionary dictionary];
                    [exif addEntriesFromDictionary:ciimage.properties];

                    // Get file name
                    NSURL *picpath = [info objectForKey:@"PHImageFileURLKey"];
                    NSString *myfilename = [picpath lastPathComponent];

                    // Get creation date
                    NSDictionary *pictiff = exif[@"{TIFF}"];
                    NSString *picdate = pictiff[@"DateTime"];

I would really appreciate some help on getting the creation date for these PNG files.

Deployment target 8.0, Xcode 7.3.1, iPhone 6, iOS 8.4

  • Check for any metadata with `pngcheck` or a similar program. If there is none, then the only "date" is in the OS file data. – Jongware Mar 23 '18 at 10:01
  • There isn't (AFAIK) a standard way to store Exif (TIFF) data in the PNG format (`'eXIf'` if suggested, but it's not in the W3C/ISO standard, and thus not much used). You may get the same information from the XMP data though, if present (in an `'iTXt'` chunk with the `'XML:com.adobe.xmp'`keyword). – Harald K Mar 26 '18 at 08:30

1 Answers1

0

Well, I was hoping I could get the file name and creation date from the same object for all the pictures but I couldn't. I still don't know why the TIFF dictionary was not available in the PNG files so I used these answers:

To get the creation date: How to get photo creation date in objective c

To get the file name: iOS8 Photos Framework: How to get the name(or filename) of a PHAsset?