【问题标题】:ALAsset timestamp returns wrong dateALAsset 时间戳返回错误的日期
【发布时间】:2011-09-26 11:34:09
【问题描述】:

我正在尝试获取图片的时间戳,我可以得到正确的经纬度值,但是时间戳总是返回当前时间,而不是图片的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];

感谢任何帮助,谢谢

【问题讨论】:

    标签: iphone objective-c alasset assetslibrary


    【解决方案1】:

    您需要使用ALAssetPropertyDate 键获取日期。

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

    【讨论】:

    • 谢谢,这将返回图像保存的日期/时间。因此,如果说使用照片应用程序编辑或拍摄图像然后传输到相机胶卷,日期/时间将是错误的
    • 好的,我找到了答案:ALAssetPropertyLocation 时间戳只包含一个时间,没有日期,肯定是一个遗漏。给我字典格式的整个元数据的是: NSDictionary *metadata = asset.defaultRepresentation.metadata;希望这对其他人有所帮助。
    • @RexMac66 您应该将其发布为答案并接受它,或者如果它有助于解决问题,请接受上面的答案。这样未来的读者就会知道什么是有效的。
    【解决方案2】:

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

    NSDictionary *metadata = asset.defaultRepresentation.metadata; 
    

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 2020-11-02
        • 2021-10-16
        • 2015-10-23
        • 1970-01-01
        • 2021-04-02
        • 1970-01-01
        • 2011-02-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多