Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed NSDate format #2

Merged
merged 1 commit into from

2 participants

@prisonerjohn

I tried a couple of EXIF readers that were ignoring any passed dates that were manually set using
- (void)setDateOriginal:(NSDate *)date
and
- (void)setDateDigitized:(NSDate *)date
so I edited the format to match the dates passed using
- (id)initWithInfoFromImagePicker:(NSDictionary *)info
and that seems to work.

Great category by the way, hope this helps!

@prisonerjohn prisonerjohn Replaced NSDates by UTC-formatted NSStrings for all date entries beca…
…use the standard NSDate format was not being parsed properly by many EXIF readers.
b3c8d50
@gpambrozio gpambrozio merged commit e261c62 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 28, 2012
  1. @prisonerjohn

    Replaced NSDates by UTC-formatted NSStrings for all date entries beca…

    prisonerjohn authored
    …use the standard NSDate format was not being parsed properly by many EXIF readers.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 4 deletions.
  1. +19 −4 GusUtils/NSMutableDictionary+ImageMetadata.m
View
23 GusUtils/NSMutableDictionary+ImageMetadata.m
@@ -22,6 +22,19 @@ @implementation NSMutableDictionary (ImageMetadataCategory)
@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 {
// Dictionary of metadata is here
@@ -112,7 +125,7 @@ - (void)setLocation:(CLLocation *)location {
if ([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:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
[locDict setObject:lngRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
@@ -205,12 +218,14 @@ - (void)setUserComment:(NSString*)comment {
}
- (void)setDateOriginal:(NSDate *)date {
- [EXIF_DICT setObject:date forKey:(NSString*)kCGImagePropertyExifDateTimeOriginal];
- [TIFF_DICT setObject:date forKey:(NSString*)kCGImagePropertyTIFFDateTime];
+ NSString *dateString = [self getUTCFormattedDate:date];
+ [EXIF_DICT setObject:dateString forKey:(NSString*)kCGImagePropertyExifDateTimeOriginal];
+ [TIFF_DICT setObject:dateString forKey:(NSString*)kCGImagePropertyTIFFDateTime];
}
- (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 {
Something went wrong with that request. Please try again.