Skip to content

Commit

Permalink
Replaced NSDates by UTC-formatted NSStrings for all date entries beca…
Browse files Browse the repository at this point in the history
…use the standard NSDate format was not being parsed properly by many EXIF readers.
  • Loading branch information
prisonerjohn committed Aug 28, 2012
1 parent dd973eb commit b3c8d50
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions GusUtils/NSMutableDictionary+ImageMetadata.m
Expand Up @@ -22,6 +22,19 @@ @implementation NSMutableDictionary (ImageMetadataCategory)


@dynamic trueHeading; @dynamic trueHeading;


- (NSString *)getUTCFormattedDate:(NSDate *)localDate {

static NSDateFormatter *dateFormatter;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];
}
NSString *dateString = [dateFormatter stringFromDate:localDate];
return dateString;
}

- (id)initWithImageSampleBuffer:(CMSampleBufferRef) imageDataSampleBuffer { - (id)initWithImageSampleBuffer:(CMSampleBufferRef) imageDataSampleBuffer {


// Dictionary of metadata is here // Dictionary of metadata is here
Expand Down Expand Up @@ -112,7 +125,7 @@ - (void)setLocation:(CLLocation *)location {
if ([self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]) { if ([self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]) {
[locDict addEntriesFromDictionary:[self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]]; [locDict addEntriesFromDictionary:[self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]];
} }
[locDict setObject:location.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp]; [locDict setObject:[self getUTCFormattedDate:location.timestamp] forKey:(NSString*)kCGImagePropertyGPSTimeStamp];
[locDict setObject:latRef forKey:(NSString*)kCGImagePropertyGPSLatitudeRef]; [locDict setObject:latRef forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
[locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude]; [locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
[locDict setObject:lngRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef]; [locDict setObject:lngRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
Expand Down Expand Up @@ -205,12 +218,14 @@ - (void)setUserComment:(NSString*)comment {
} }


- (void)setDateOriginal:(NSDate *)date { - (void)setDateOriginal:(NSDate *)date {
[EXIF_DICT setObject:date forKey:(NSString*)kCGImagePropertyExifDateTimeOriginal]; NSString *dateString = [self getUTCFormattedDate:date];
[TIFF_DICT setObject:date forKey:(NSString*)kCGImagePropertyTIFFDateTime]; [EXIF_DICT setObject:dateString forKey:(NSString*)kCGImagePropertyExifDateTimeOriginal];
[TIFF_DICT setObject:dateString forKey:(NSString*)kCGImagePropertyTIFFDateTime];
} }


- (void)setDateDigitized:(NSDate *)date { - (void)setDateDigitized:(NSDate *)date {
[EXIF_DICT setObject:date forKey:(NSString*)kCGImagePropertyExifDateTimeDigitized]; NSString *dateString = [self getUTCFormattedDate:date];
[EXIF_DICT setObject:dateString forKey:(NSString*)kCGImagePropertyExifDateTimeDigitized];
} }


- (void)setMake:(NSString*)make model:(NSString*)model software:(NSString*)software { - (void)setMake:(NSString*)make model:(NSString*)model software:(NSString*)software {
Expand Down

0 comments on commit b3c8d50

Please sign in to comment.