PhotoKit使用简单总结

2019-08-19  本文已影响0人  Console_Liu
photoKit的基本构成有:
概念图:
photokit.png
eg:
// 获得系统相机胶卷(不同iOS系统版本,中文名可能不一致,iOS 12:所有照片,iOS 13:最近项目)
PHAssetCollection *cameraRolls = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil].firstObject;
//获取所有自定义相簿
PHFetchResult *albumCollections = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:(PHAssetCollectionSubtype)0 options:nil];
// 获得系统视频相簿
PHFetchResult *videoCollections = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumVideos options:nil];
// 通过这个方法以及PHAssetCollectionType和PHAssetCollectionSubtype参数,就能获取你想要的相册了。
+ (PHFetchResult *)fetchAssetCollectionsWithType:(PHAssetCollectionType)type subtype:(PHAssetCollectionSubtype)subtype options:(nullable PHFetchOptions *)options;

// PHAssetCollectionType的所有参数
typedef NS_ENUM(NSInteger, PHAssetCollectionType) {
    PHAssetCollectionTypeAlbum      = 1, // 相册,系统外的
    PHAssetCollectionTypeSmartAlbum = 2, // 智能相册,系统自己分配和归纳的
    PHAssetCollectionTypeMoment     = 3, // 时刻,系统自动通过时间和地点生成的分组
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);

typedef NS_ENUM(NSInteger, PHAssetCollectionSubtype) {

    // PHAssetCollectionTypeAlbum regular subtypes
    PHAssetCollectionSubtypeAlbumRegular         = 2, // 在iPhone中自己创建的相册
    PHAssetCollectionSubtypeAlbumSyncedEvent     = 3, 
    PHAssetCollectionSubtypeAlbumSyncedFaces     = 4, // 从图片app中导入的人物照片
    PHAssetCollectionSubtypeAlbumSyncedAlbum     = 5, // 从图片app导入的相册
    PHAssetCollectionSubtypeAlbumImported        = 6,

    // PHAssetCollectionTypeAlbum shared subtypes
    PHAssetCollectionSubtypeAlbumMyPhotoStream   = 100, // 照片流,照片流和iCloud有关,如果在设置里关闭了iCloud开关,就获取不到了
    PHAssetCollectionSubtypeAlbumCloudShared     = 101, // iCloud的共享相册,点击照片上的共享tab创建后就能拿到了,但是前提是你要在设置中打开iCloud的共享开关(打开后才能看见共享tab)

    // PHAssetCollectionTypeSmartAlbum subtypes
    PHAssetCollectionSubtypeSmartAlbumGeneric    = 200, 
    PHAssetCollectionSubtypeSmartAlbumPanoramas  = 201, // 全景图、全景照片
    PHAssetCollectionSubtypeSmartAlbumVideos     = 202, // 视频
    PHAssetCollectionSubtypeSmartAlbumFavorites  = 203, // 标记为喜欢、收藏
    PHAssetCollectionSubtypeSmartAlbumTimelapses = 204, // 延时拍摄、定时拍摄
    PHAssetCollectionSubtypeSmartAlbumAllHidden  = 205, // 隐藏的
    PHAssetCollectionSubtypeSmartAlbumRecentlyAdded = 206, // 最近添加的、近期添加
    PHAssetCollectionSubtypeSmartAlbumBursts     = 207, // 连拍
    PHAssetCollectionSubtypeSmartAlbumSlomoVideos = 208,
    PHAssetCollectionSubtypeSmartAlbumUserLibrary = 209, // 相机胶卷
    PHAssetCollectionSubtypeSmartAlbumSelfPortraits PHOTOS_AVAILABLE_IOS_TVOS(9_0, 10_0) = 210, // 使用前置摄像头拍摄的作品
    PHAssetCollectionSubtypeSmartAlbumScreenshots PHOTOS_AVAILABLE_IOS_TVOS(9_0, 10_0) = 211, // 屏幕截图
    PHAssetCollectionSubtypeSmartAlbumDepthEffect PHOTOS_AVAILABLE_IOS_TVOS(10_2, 10_1) = 212,
    PHAssetCollectionSubtypeSmartAlbumLivePhotos PHOTOS_AVAILABLE_IOS_TVOS(10_3, 10_2) = 213, // Live Photo资源
    PHAssetCollectionSubtypeSmartAlbumAnimated PHOTOS_AVAILABLE_IOS_TVOS(11_0, 11_0) = 214,
    PHAssetCollectionSubtypeSmartAlbumLongExposures PHOTOS_AVAILABLE_IOS_TVOS(11_0, 11_0) = 215,
    // Used for fetching, if you don't care about the exact subtype
    PHAssetCollectionSubtypeAny = NSIntegerMax
} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);

reference
1、iOS 基于PhotoKit框架的自定义相册
2、基于 PhotoKit 框架封装

上一篇下一篇

猜你喜欢

热点阅读