【问题标题】:Fetch only albums in a PHCollectionList仅获取 PHCollectionList 中的专辑
【发布时间】:2015-05-03 17:50:24
【问题描述】:

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

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

【问题讨论】:

    标签: ios ios8 photokit phasset phfetchoptions


    【解决方案1】:

    你试过了吗:

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

    您的&lt;ftilerType&gt; 可以是PHCollectionListType 中的任何内容:

    • PHCollectionListTypeMomentList - 由 iPhone 创建的时刻(基本上所有照片都归入年份和收藏)
    • PHCollectionListTypeFolder - 用户创建的相册(文件夹)
    • PHCollectionListTypeSmartFolder - iPhone 自动创建的智能文件夹

    【讨论】:

      【解决方案2】:

      您可以使用谓词来指定专辑的名称,并使用它从 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);
              }
            }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-28
        相关资源
        最近更新 更多