3

APHCollectionList是可以包含任意数量的专辑和/或文件夹的文件夹。我目前正在通过 获取列表中的集合PHCollection.fetchCollectionsInCollectionList(list, options: nil)

这可能会返回PHAssetCollection或类型的对象PHCollectionList。我只对知道PHAssetCollection该列表中的 s 感兴趣。文档声明您可以使用 fetch 选项应用过滤谓词以返回数据的子集,但我不知道如何使用它来仅获取专辑。您如何使用PHFetchOptions才能PHAssetCollection在给定的情况下仅返回 s PHCollectionList

4

2 回答 2

1

你有没有尝试过:

    [PHCollectionList fetchCollectionListsWithType:<filterType> subtype:nil optionsnil]

<ftilerType>可能来自哪里PHCollectionListType

  • PHCollectionListTypeMomentList - 由 iPhone 创建的时刻(基本上所有照片都分组到年份和收藏中)
  • PHCollectionListTypeFolder - 用户创建的相册(文件夹)
  • PHCollectionListTypeSmartFolder - iPhone 自动创建的智能文件夹
于 2015-07-01T10:43:18.603 回答
0

您可以使用谓词来指定专辑的名称,并使用它从 collectionList 中获取特定的专辑。

PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", ABC];

PHFetchResult *collectionsFetchResult = [PHCollection fetchCollectionsInCollectionList:self.collectionList options:fetchOptions];

PHAssetCollection *ABCAlbum = collectionsResult.firstObject;
  NSLog(@"ABC album details: %@", ABCAlbum);

或者您可以将 nil 放入 options 并获取 List 中的所有 AssetCollections。

    PHFetchResult *collectionsFR = [PHCollection fetchCollectionsInCollectionList:list options:nil];
      if ( collectionsFR.count > 0) {
        for ( PHAssetCollection *collection in collectionsFR) {
          // do something with each album
          NSLog(@"collection is %@", collection);
        }
      }
于 2015-10-02T19:56:49.997 回答