PHFetchResult получить все фотографии и отсортировать по дате несовместимо

I'm trying to build a simply photo picker that has two options for now: Recents and Favorites. What I'm doing is trying to get all the photos by the creationDate however this is giving back images in the wrong order in my data source. There's photos from years ago at the beginning of the data source, and photos that are less than a few minutes old scattered throughout. I think the issue is that I need to tell the main fetchResult the sort order first, however I don't think it's possible: Unsupported sort descriptor in fetch options: (creationDate, ascending, compare:

I'd appreciate any help offered. Code:

@property (nonatomic, strong) NSMutableOrderedSet *recentsDataSource;
@property (nonatomic, strong) NSMutableOrderedSet *favoritesDataSource;

- (void)setup
{
    PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum | PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];

    for (PHAssetCollection *sub in fetchResult)
    {
        PHFetchOptions *fetchOptions = [[PHFetchOptions alloc]init];

        fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];

        PHFetchResult *assetsInCollection = [PHAsset fetchAssetsInAssetCollection:sub options:fetchOptions];

        for (PHAsset *asset in assetsInCollection)
        {
            [self.recentsDataSource addObject:asset];

            if (asset.isFavorite)
            {
                [self.favoritesDataSource addObject:asset];
            }
        }
    }
}
7 голосов | спросил klcjr89 2 J0000006Europe/Moscow 2015, 20:32:43

0 ответов


Похожие вопросы

Популярные теги

security × 330linux × 316macos × 2827 × 268performance × 244command-line × 241sql-server × 235joomla-3.x × 222java × 189c++ × 186windows × 180cisco × 168bash × 158c# × 142gmail × 139arduino-uno × 139javascript × 134ssh × 133seo × 132mysql × 132