为什么我在PHAsset中有两种不同的日历类型的creationDate?

时间:2017-02-07 08:22:51

标签: ios phasset

我有这段代码,它尝试获取creationDate

排序的所有图片
PHFetchOptions *options = [[PHFetchOptions alloc] init];
    options.sortDescriptors = @[
        [NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES],
    ];

    switch (type) {
        case MMAssetsPhoto:{
            fetch = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:options];
            break;
        }
        case MMAssetsVideo:{
            options.includeAssetSourceTypes = PHAssetSourceTypeiTunesSynced | PHAssetSourceTypeCloudShared | PHAssetSourceTypeUserLibrary | PHAssetSourceTypeNone;
            fetch = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:options];
            break;
        }
        default:{
            options.includeAssetSourceTypes = PHAssetSourceTypeUserLibrary;
            fetch  = [PHAsset fetchAssetsWithOptions:options];
            break;
        }
    }
    [fetch enumerateObjectsUsingBlock:^(PHAsset * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        EkoLog(@"=======");
        EkoLog(@"asset %@", obj);
        EkoLog(@"create date %@", obj.creationDate);
        EkoLog(@"modification date %@", obj.modificationDate);
    }];

但这是我为某些图片获取的日志

=======
asset <PHAsset: 0x10d075bd0> D27FB9E1-53F0-4884-A0EA-C6E839A6A0FB/L0/001 mediaType=1/0, sourceType=1, (4032x3024), creationDate=2017-01-05 11:54:50 +0000, location=0, hidden=0, favorite=0
create date 2017-01-05 11:54:50 +0000
modification date 2017-01-05 11:54:50 +0000
=======
asset <PHAsset: 0x10d075d20> 18EA7D99-9FB7-4941-9E7A-E0C68F5F791B/L0/001 mediaType=1/0, sourceType=1, (4032x3024), creationDate=2560-01-05 14:03:59 +0000, location=0, hidden=0, favorite=0
create date 2560-01-05 14:03:59 +0000
modification date 2017-01-05 14:04:00 +0000
=======
asset <PHAsset: 0x10d075e70> 41871302-553F-4BF0-AA8C-E6AC177E0068/L0/001 mediaType=1/0, sourceType=1, (3024x4032), creationDate=2560-01-05 14:15:57 +0000, location=0, hidden=0, favorite=0
create date 2560-01-05 14:15:57 +0000
modification date 2017-02-04 21:08:48 +0000

正如您所注意到的,有一些图片在佛教日历中获得creationDate25602017。这导致排序将佛教日历的图像排列在最后,这是错误的。

我不知道为什么这是正确的,因为当我从modificationDate看到它时,我得到了正确的2017

无论如何要解决这个问题?

更新

对我来说看起来像苹果虫,因为在照片应用程序中,这些图像是在3103年......

1 个答案:

答案 0 :(得分:1)

没有Apple bug。图像中存储了不正确的日期信息。 NSDate未连接到日历。您可以将其视为自1970年以来的秒数的简单包装。日志不使用不同的日历打印 - 日期没有日历。这些图片的日期是公历年2560 - 543年。

我认为有一个程序员不理解日历和日期之间的差异,并且在图像的元数据中存储了错误的日期信息。这些图像的来源是什么?