通过以下方法获取相册图片:
+ (PHFetchResult *)fetchAssetCollectionsWithType:(PHAssetCollectionType)type subtype:(PHAssetCollectionSubtype)subtype options:(nullable PHFetchOptions *)options;
PHAssetCollectionType类型:
typedef NS_ENUM(NSInteger, PHAssetCollectionType) {
PHAssetCollectionTypeAlbum = 1, // 用户自定义相册
PHAssetCollectionTypeSmartAlbum = 2, // 系统相册
PHAssetCollectionTypeMoment API_DEPRECATED("Will be removed in a future release", ios(8, 13), tvos(10, 13)) API_UNAVAILABLE(macos) = 3, // 系统相册,按照每日区分
};
选择相册类型为PHAssetCollectionTypeAlbum(用户自定义相册)时:
typedef NS_ENUM(NSInteger, PHAssetCollectionSubtype) {
// PHAssetCollectionTypeAlbum regular subtypes
PHAssetCollectionSubtypeAlbumRegular = 2,// 所有自定义相册
PHAssetCollectionSubtypeAlbumSyncedEvent = 3,// 空
PHAssetCollectionSubtypeAlbumSyncedFaces = 4,// 空
PHAssetCollectionSubtypeAlbumSyncedAlbum = 5,// 空
PHAssetCollectionSubtypeAlbumImported = 6,// 空
// PHAssetCollectionTypeAlbum shared subtypes
PHAssetCollectionSubtypeAlbumMyPhotoStream = 100,// 空
PHAssetCollectionSubtypeAlbumCloudShared = 101,// 空
// PHAssetCollectionTypeSmartAlbum subtypes
PHAssetCollectionSubtypeSmartAlbumGeneric = 200,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumPanoramas = 201,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumVideos = 202,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumFavorites = 203,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumTimelapses = 204,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumAllHidden = 205,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumRecentlyAdded = 206,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumBursts = 207,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumSlomoVideos = 208,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumUserLibrary = 209,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumSelfPortraits API_AVAILABLE(ios(9)) = 210,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumScreenshots API_AVAILABLE(ios(9)) = 211,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumDepthEffect API_AVAILABLE(macos(10.13), ios(10.2), tvos(10.1)) = 212,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumLivePhotos API_AVAILABLE(macos(10.13), ios(10.3), tvos(10.2)) = 213,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumAnimated API_AVAILABLE(macos(10.15), ios(11), tvos(11)) = 214,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumLongExposures API_AVAILABLE(macos(10.15), ios(11), tvos(11)) = 215,// 所有自定义相册
PHAssetCollectionSubtypeSmartAlbumUnableToUpload API_AVAILABLE(macos(10.15), ios(13), tvos(13)) = 216,// 所有自定义相册
// Used for fetching, if you don't care about the exact subtype
PHAssetCollectionSubtypeAny = NSIntegerMax// 所有自定义相册
};
选择相册类型为PHAssetCollectionTypeSmartAlbum(系统相册)时:
所有系统相册:全景照片、动图、最近删除、无法上传、慢动作、截屏、已隐藏、个人收藏、自拍、连拍快照、最近项目、实况照片、视频、最近添加、延时摄影、长曝光、人像。
typedef NS_ENUM(NSInteger, PHAssetCollectionSubtype) {
// PHAssetCollectionTypeAlbum regular subtypes
PHAssetCollectionSubtypeAlbumRegular = 2,// 所有系统相册
PHAssetCollectionSubtypeAlbumSyncedEvent = 3,// 所有系统相册
PHAssetCollectionSubtypeAlbumSyncedFaces = 4,// 所有系统相册
PHAssetCollectionSubtypeAlbumSyncedAlbum = 5,// 所有系统相册
PHAssetCollectionSubtypeAlbumImported = 6,// 所有系统相册
// PHAssetCollectionTypeAlbum shared subtypes
PHAssetCollectionSubtypeAlbumMyPhotoStream = 100,// 所有系统相册
PHAssetCollectionSubtypeAlbumCloudShared = 101,// 所有系统相册
// PHAssetCollectionTypeSmartAlbum subtypes
PHAssetCollectionSubtypeSmartAlbumGeneric = 200,// 没有任何数据
PHAssetCollectionSubtypeSmartAlbumPanoramas = 201,// 全景照片
PHAssetCollectionSubtypeSmartAlbumVideos = 202,// 视频
PHAssetCollectionSubtypeSmartAlbumFavorites = 203,// 个人收藏
PHAssetCollectionSubtypeSmartAlbumTimelapses = 204,// 延时摄影
PHAssetCollectionSubtypeSmartAlbumAllHidden = 205,// 已隐藏
PHAssetCollectionSubtypeSmartAlbumRecentlyAdded = 206,// 最近添加
PHAssetCollectionSubtypeSmartAlbumBursts = 207,// 连拍快照
PHAssetCollectionSubtypeSmartAlbumSlomoVideos = 208,// 慢动作
PHAssetCollectionSubtypeSmartAlbumUserLibrary = 209,// 最近项目
PHAssetCollectionSubtypeSmartAlbumSelfPortraits API_AVAILABLE(ios(9)) = 210,// 自拍
PHAssetCollectionSubtypeSmartAlbumScreenshots API_AVAILABLE(ios(9)) = 211,// 截屏
PHAssetCollectionSubtypeSmartAlbumDepthEffect API_AVAILABLE(macos(10.13), ios(10.2), tvos(10.1)) = 212,// 人像
PHAssetCollectionSubtypeSmartAlbumLivePhotos API_AVAILABLE(macos(10.13), ios(10.3), tvos(10.2)) = 213,// 实况照片
PHAssetCollectionSubtypeSmartAlbumAnimated API_AVAILABLE(macos(10.15), ios(11), tvos(11)) = 214,// 动图
PHAssetCollectionSubtypeSmartAlbumLongExposures API_AVAILABLE(macos(10.15), ios(11), tvos(11)) = 215,// 长曝光
PHAssetCollectionSubtypeSmartAlbumUnableToUpload API_AVAILABLE(macos(10.15), ios(13), tvos(13)) = 216,// 无法上传
// Used for fetching, if you don't care about the exact subtype
PHAssetCollectionSubtypeAny = NSIntegerMax// 全景照片、动图、慢动作、截屏、已隐藏、个人收藏、自拍、连拍快照、最近项目、实况照片、视频、延时摄影、长曝光、人像(少了这三个:最近删除、无法上传、最近添加)
};
选择相册类型为PHAssetCollectionTypeMoment(系统相册)时:
返回"最近项目"中的所有相片,按照每日区分,选任意PHAssetCollectionSubtype结果不变
以上为自身测试,如有问题可发私信
苹果源文档:https://developer.apple.com/documentation/photokit/phassetcollectionsubtype