【问题标题】:PHFetchResult for Custom Album Only仅限自定义相册的 PHFetchResult
【发布时间】:2015-10-18 04:35:21
【问题描述】:

我只是想将位于名为“MyFolder”的自定义文件夹中的照片访问到我的 UICollectionView。我可以使用以下代码轻松使用“所有照片和视频”,但我无法弄清楚如何过滤结果以仅包含我的文件夹名称:

PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];

PHFetchResult *videos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:allPhotosOptions];

[videos enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
      //add assets to array
}];

我试过用这个:

allPhotosOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"Coached"];

但它不起作用。有人可以帮我吗?

【问题讨论】:

    标签: ios uicollectionview phfetchoptions


    【解决方案1】:

    哇。经过大约5个多小时的痛苦。这很简单。这是有效的代码:

    __block PHAssetCollection *collection;
    
    // Find the album
    PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
    fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"YOUR_CUSTOM_ALBUM_NAME"];
    collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
                                                          subtype:PHAssetCollectionSubtypeAny
                                                          options:fetchOptions].firstObject;
    
    PHFetchResult *collectionResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
    
    [collectionResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
    
    
            //add assets to an array for later use in the uicollectionviewcell
    
        }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      • 2014-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多