2011-07-01 85 views
3

我想獲取圖像的時間戳,我可以得到正確的經度和緯度值,但時間戳總是返回當前時間,而不是圖像的EXIF時間。ALAsset時間戳返回錯誤的日期

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]; 

讚賞任何幫助,感謝

回答

3

OK我找到了答案 什麼給我的全部元數據字典格式爲:

NSDictionary *metadata = asset.defaultRepresentation.metadata; 

//希望這會幫助別人。

13

您將需要使用ALAssetPropertyDate鍵搞定的日期。

NSDate * date = [asset valueForProperty:ALAssetPropertyDate]; 
/* Use the `NSDateFormatter` instance to print the date */ 
+2

謝謝,這將返回保存圖像的日期/時間。所以,如果說一個圖像被編輯或拍攝的照片應用程序,然後轉移到相機膠捲,日期/時間將是錯誤的 – RexMac66

+0

好吧,我找到了答案:ALAssetPropertyLocation時間戳包含一個時間只有沒有日期,肯定是一個遺漏。 什麼給了我字典格式的整個元數據是: NSDictionary * metadata = asset.defaultRepresentation.metadata; 希望這可以幫助別人。 – RexMac66

+0

@ RexMac66您應該將其作爲答案發布並接受它,或者如果它有助於解決問題,請接受上面的答案。這樣未來的讀者會知道什麼工作。 – chown

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! 
          }]; 
 
+0

謝謝我會檢查出來。 – RexMac66

相關問題