3

我正在尝试获取图像的时间戳,我可以获得正确的纬度和经度值,但时间戳总是返回当前时间,而不是图像的 EXIF 时间。

ALAssetsLibraryAssetForURLResultBlock resultsBlock = ^(ALAsset *asset) {
    CLLocation *imageLoc = [asset valueForProperty:ALAssetPropertyLocation];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd/MM/YY HH:mm:ss"];
    NSString *trailTime = [formatter stringFromDate:imageLoc.timestamp];
    NSLog(@"---+++ image TimeStamp: %@", trailTime);
    [formatter release];

任何帮助表示赞赏,谢谢

4

3 回答 3

13

您将需要使用ALAssetPropertyDate密钥获取日期。

NSDate * date = [asset valueForProperty:ALAssetPropertyDate];
/* Use the `NSDateFormatter` instance to print the date */
于 2011-07-01T05:47:13.273 回答
3

好的,我找到了答案给了我字典格式的整个元数据的是:

NSDictionary *metadata = asset.defaultRepresentation.metadata; 

//希望这对其他人有帮助。

于 2012-03-05T03:34:39.937 回答
1

似乎您正在获取位置以获取日期。您应该执行以下操作:


    ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];

    [assetsLib enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                             usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

                                 [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {

                                     //If you'd want to directly fetch from it's external property, which seems more appropriate.
                                     NSDate *date = [result valueForProperty:ALAssetPropertyDate];
                                     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                                     [dateFormatter setLocale:[NSLocale currentLocale]];
                                     [dateFormatter setDateFormat:@"dd-mm-yyyy hh:mm:ss ZZZ"];
                                     NSString *stringDate = [dateFormatter stringFromDate:date];

                                     //If you'd want to fetch the date from metaData
                                     ALAssetRepresentation *assetRep = [result defaultRepresentation];
                                     NSDictionary *dictionaryOfMetaData = [assetRep metadata];

                                     NSLog(@"dictionary:%@ \n \
                                           date:%@ \n \
                                           StringDate:%@", [[dictionaryOfMetaData valueForKey:@"{TIFF}"] valueForKey:@"DateTime"],
                                           date,
                                           stringDate);
                                 }];
                             }
                           failureBlock:^(NSError *error) {
                              //Handle Error!  
                           }];

于 2013-01-21T08:10:29.497 回答