ALAssetPropertyDate返回"错误"日期

Uxx*_*ish 4 xcode exif date objective-c

我目前正在开展一个项目,我需要阅读一些(纬度,经度和日期)EXIF数据.位置数据似乎是正确的,但我得到的日期似乎是"最后修改日期"日期.

{
    CLLocation *loc = [asset valueForProperty:ALAssetPropertyLocation];
    NSDate *date = [asset valueForProperty:ALAssetPropertyDate];
    //Returns Last modified date(Picture was taken ... let's say september 
    //last year and it would return the date and time I 'modified' the image).
    NSString *latitude  = [NSString stringWithFormat:@"%g",loc.coordinate.latitude];//Returns correct Latitude
    NSString *longitude = [NSString stringWithFormat:@"%g",loc.coordinate.longitude];//Returns correct Longitude
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:我做的事情是非常错误的,还是这种预期的行为.我也尝试使用loc.timestamp而不是[asset valueForProperty:ALAssetPropertyDate]但这些返回相同的日期.任何帮助是极大的赞赏 !

hir*_*shi 5

你也可以DateTimeOriginal通过Exif ALAsset.

NSDateFormatter *dateFormatter = [[NSDateFormatter new] autorelease];
dateFormatter.dateFormat = @"y:MM:dd HH:mm:ss";
NSDate *date = [dateFormatter dateFromString:[[[[asset defaultRepresentation] metadata] objectForKey:@"{Exif}"] objectForKey:@"DateTimeOriginal"]];
Run Code Online (Sandbox Code Playgroud)

从资产中获取元数据需要在内存(或整个图像文件?)上加载Exif标头,并且上述方法似乎使用自动释放池作为内存空间.如果对数千张图像进行批处理,这可能会导致内存不足或更严重的崩溃.

要解决内存不足问题,您可以使用Ad-Hoc自动释放池.

NSDateFormatter *dateFormatter = [[NSDateFormatter new] autorelease];
dateFormatter.dateFormat = @"y:MM:dd HH:mm:ss";
for (ALAsset *asset in thousandsOfAssets) {
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    NSDate *date = [dateFormatter dateFromString:[[[[asset defaultRepresentation] metadata] objectForKey:@"{Exif}"] objectForKey:@"DateTimeOriginal"]];
    // do something
    [pool release];
}
Run Code Online (Sandbox Code Playgroud)

编辑:更正错误的dateFormat(SS - > ss).谢谢@ code-roadie