热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

仅获取PHCollectionList中的相册-FetchonlyalbumsinaPHCollectionList

APHCollectionListisafolderthatcouldcontainanynumberofalbumsandorfolders.Iamcurrentl

A PHCollectionList is a folder that could contain any number of albums and/or folders. I am currently fetching the collections within the list via PHCollection.fetchCollectionsInCollectionList(list, options: nil).

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

This could return objects of type PHAssetCollection or PHCollectionList. I am only interested in knowing of the PHAssetCollections in that list. The docs state you can apply a filter predicate using the fetch options in order to return a subset of the data, but I don't see how I would use that in order to only get albums. How do you use PHFetchOptions in order to return only PHAssetCollections in a given PHCollectionList?

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

2 个解决方案

#1


Have you tried:

你有没有尝试过:

    [PHCollectionList fetchCollectionListsWithType: subtype:nil optionsnil]

Where your could be anything from PHCollectionListType:

您的 可以是PHCollectionListType中的任何内容:

  • PHCollectionListTypeMomentList - Moments created by iPhone (essentially all photos grouped into Year and Collections)
  • PHCollectionListTypeMomentList - 由iPhone创建的时刻(基本上所有照片分组为年份和集合)

  • PHCollectionListTypeFolder - user created Albums (folders)
  • PHCollectionListTypeFolder - 用户创建的相册(文件夹)

  • PHCollectionListTypeSmartFolder - Smart folders created by the iPhone automatically
  • PHCollectionListTypeSmartFolder - 由iPhone自动创建的智能文件夹

#2


You can use predicate to specify the album's name and use it to fetch specific Album from the collectionList.

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

Or you can put nil in options and get all of the AssetCollections in the List.

或者您可以将nil置于选项中并获取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);
        }
      }

推荐阅读
author-avatar
我病态见不得你跟别人恩爱
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有