Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixed NSDate format #2

Merged
merged 1 commit into from Aug 28, 2012
Jump to file or symbol
Failed to load files and symbols.
+19 −4
Split
@@ -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 {