ALAsset 时间戳返回错误日期

发布于 2024-11-17 21:48:59 字数 526 浏览 3 评论 0原文

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

任何帮助表示赞赏,谢谢

I am trying to get the timestamp of images, I can get the correct latitude and longitude values, but the timestamp always returns the current time, not the EXIF time of the image.

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

Any help appreciated, thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘦怹 2024-11-24 21:48:59

您需要使用 ALAssetPropertyDate 键。

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

You will need to get the date using ALAssetPropertyDate key.

NSDate * date = [asset valueForProperty:ALAssetPropertyDate];
/* Use the `NSDateFormatter` instance to print the date */
肩上的翅膀 2024-11-24 21:48:59

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

NSDictionary *metadata = asset.defaultRepresentation.metadata; 

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

OK I found the answer
What gave me the entire metadata in dictionary format was:

NSDictionary *metadata = asset.defaultRepresentation.metadata; 

//Hope this helps others.

您的好友蓝忘机已上羡 2024-11-24 21:48:59

您似乎正在获取位置来获取日期。你应该做类似以下的事情:


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

It seems like you're fetching location to get the date. you should be doing something like the following:


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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文