PHCollectionList

包含了一組Photos資源集合的表現形式,例如一個時刻中的“年”或者用戶創建的相簿文件夾。

一、概述

Photos框架中,集合對象(包括資源集合)不能直接引用它們自己內部的成員對象,并且也沒有其他的對象能夠直接引用集合對象。想要調用一個集合列表中的成員,請使用PHCollection的類方法獲取,例如+ (PHFetchResult<PHCollection *> *)fetchCollectionsInCollectionList:(PHCollectionList *)collectionList options:(PHFetchOptions *)options;。想要在集合列表的頂層(例如一個沒有上級文件夾的相簿文件夾)中查找一個對象,請使用+ (PHFetchResult<PHCollection *> *)fetchTopLevelUserCollectionsWithOptions:(PHFetchOptions *)options;方法。

資源以及資源集合一樣,集合列表也是不可以被修改的。想要創建、重命名、刪除一個集合列表,或者想要添加、刪除、重置集合列表中的內容,請在PHPhotoLibrary中的更改回調中創建一個PHCollectionListChangeRequest對象。想要獲得更多關于更改請求以及更改回調的內容,清查看PHPhotoLibrary。

二、內容

1. 獲取集合列表

+ (PHFetchResult<PHCollectionList *> *)fetchCollectionListsContainingCollection:(PHCollection *)collection options:(nullable PHFetchOptions *)options;

獲取包含給定的集合集合列表
不同類型的集合有可能被包含在不同的東西中。例如,一個PHAssetCollectionTypeAlbum類型的資源集合可能被包含在一個文件夾中,而不是在一個集合列表中。一個文件夾也有可能被包含在另一個文件夾中。一個PHAssetCollectionTypeMoment類型的資源集合總是被包含在兩個集合列表中:一個“當前”時刻,一個“年”時刻。

+ (PHFetchResult<PHCollectionList *> *)fetchCollectionListsWithLocalIdentifiers:(NSArray<NSString *> *)identifiers options:(nullable PHFetchOptions *)options;

根據給定的本地設備唯一標識獲取對應的集合列表。

+ (PHFetchResult<PHCollectionList *> *)fetchCollectionListsWithType:(PHCollectionListType)collectionListType subtype:(PHCollectionListSubtype)subtype options:(nullable PHFetchOptions *)options;

獲取給定類型的集合列表

PHCollectionListType

typedef NS_ENUM(NSInteger, PHCollectionListType) {
    PHCollectionListTypeMomentList    = 1, // 包含了PHAssetCollectionTypeMoment類型的資源集合的列表
    PHCollectionListTypeFolder        = 2, // 包含了PHAssetCollectionTypeAlbum類型或PHAssetCollectionTypeSmartAlbum類型的資源集合的列表
    PHCollectionListTypeSmartFolder   = 3, // 同步到設備的智能文件夾的列表
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);

PHCollectionListSubtype

typedef NS_ENUM(NSInteger, PHCollectionListSubtype) {
    // PHCollectionListTypeMomentList的子類型
    PHCollectionListSubtypeMomentListCluster    = 1, // 時刻
    PHCollectionListSubtypeMomentListYear       = 2, // 年度
    // PHCollectionListTypeFolder的子類型
    PHCollectionListSubtypeRegularFolder        = 100, // 包含了其他文件夾或者相簿的文件夾
    // PHCollectionListTypeSmartFolder的子類型
    PHCollectionListSubtypeSmartFolderEvents    = 200, // 包含了一個或多個從iPhone同步的事件的智能文件夾
    PHCollectionListSubtypeSmartFolderFaces     = 201, // 包含了一個或多個從iPhone同步的面孔(人物)的智能文件夾
    // 如果你不關心子類型是什么,則使用下面這個
    PHCollectionListSubtypeAny = NSIntegerMax
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);
+ (PHFetchResult<PHCollectionList *> *)fetchMomentListsWithSubtype:(PHCollectionListSubtype)momentListSubtype containingMoment:(PHAssetCollection *)moment options:(nullable PHFetchOptions *)options;

獲取給定類型的并且包含給定的時刻集合列表。

+ (PHFetchResult<PHCollectionList *> *)fetchMomentListsWithSubtype:(PHCollectionListSubtype)momentListSubtype options:(nullable PHFetchOptions *)options;

獲取給定類型的集合列表。

2. 獲取集合列表數據

@property (nonatomic, assign, readonly) PHCollectionListType collectionListType;

The type of asset collection group that the collection list represents.
A collection list may represent an upper level of the Moments hierarchy shown in the Photos app, a folder that contains albums, or a smart folder synced from iPhoto. See PHCollectionListType.

@property (nonatomic, assign, readonly) PHCollectionListSubtype collectionListSubtype;

The type of asset collection grouping the collection list represents.
Use subtypes to make minor distinctions between collection lists of the same type, such as moment clusters and moment years. See PHCollectionListSubtype.

@property (nonatomic, strong, readonly, nullable) NSDate *startDate;

集合列表中所有資源中最早的一個的創建日期。
這個屬性只對類型為PHCollectionListTypeMomentList集合列表有效,對于其他的類型的集合列表這個屬性的值為nil。

@property (nonatomic, strong, readonly, nullable) NSDate *endDate;

集合列表中所有資源中最近的一個的創建日期。
這個屬性只對類型為PHCollectionListTypeMomentList集合列表有效,對于其他的類型的集合列表這個屬性的值為nil。

@property (nonatomic, strong, readonly) NSArray<NSString *> *localizedLocationNames;

一組集合定位地點的名字。
對于一組時刻集合列表,正如你在照片應用中看到的那樣,這個屬性列出了這一組時刻中的定位地點的名字。對于其他類型的集合列表,這個屬性的值為nil。

3. 創建臨時集合列表

+ (PHCollectionList *)transientCollectionListWithCollections:(NSArray<PHCollection *> *)collections title:(nullable NSString *)title;

創建一個包含了給定的資源集合集合列表。

+ (PHCollectionList *)transientCollectionListWithCollectionsFetchResult:(PHFetchResult<PHCollection *> *)fetchResult title:(nullable NSString *)title;

創一個包含了給定的獲取結果中的資源集合集合列表

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容