iOS PHCollectionList详解

来源:互联网 发布:大麦网抢票软件个人版 编辑:程序博客网 时间:2024/04/27 06:30

iOS
PHCollectionListType

PHCollectionListSubtype

详解

typedef NS_ENUM(NSInteger, PHCollectionListType) {    PHCollectionListTypeMomentList    = 1,//按照图片的时刻既时间进行分类    PHCollectionListTypeFolder        = 2,//按照目录分类    PHCollectionListTypeSmartFolder   = 3,//按照智能目录分类} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);typedef NS_ENUM(NSInteger, PHCollectionListSubtype) {    // PHCollectionListTypeMomentList subtypes    PHCollectionListSubtypeMomentListCluster    = 1,//按照族群分类    PHCollectionListSubtypeMomentListYear       = 2,//按照年份分类    // PHCollectionListTypeFolder subtypes    PHCollectionListSubtypeRegularFolder        = 100,    // PHCollectionListTypeSmartFolder subtypes    PHCollectionListSubtypeSmartFolderEvents    = 200,    PHCollectionListSubtypeSmartFolderFaces     = 201,    // Used for fetching if you don't care about the exact subtype    PHCollectionListSubtypeAny = NSIntegerMax} PHOTOS_ENUM_AVAILABLE_IOS_TVOS(8_0, 10_0);在实际测试中发现PHCollectionListType 为PHCollectionListTypeFolder或PHCollectionListTypeSmartFolder使用如下方法测试 发现都是空 这两个分类暂时不做分析 估计用处不大那就分析PHCollectionListTypeMomentList这个在PHCollectionListType为PHCollectionListTypeMomentList 分别测试PHCollectionListSubtype发现PHCollectionListSubtypeMomentListCluster和PHCollectionListSubtypeMomentListYear有数据 并且数据相同其他的都没有数据可以发现对于list使用 PHCollectionListTypeMomentList 和 (PHCollectionListSubtypeMomentListCluster和PHCollectionListSubtypeMomentListYear)都行就选第一个PHCollectionListSubtypeMomentListCluster吧。/** 按照每天的数据对照片进行排序 */- (void)getSystemContentImages{//    PHFetchResult *fetchResult = [PHCollectionList fetchMomentListsWithSubtype:PHCollectionListSubtypeAny options:nil ];//    //    PHFetchResult *collectionlists = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeSmartFolder subtype:PHCollectionListSubtypeAny options:nil];//    PHFetchResult *collectionlists1 = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeMomentList subtype:PHCollectionListSubtypeMomentListYear options:nil];    PHFetchResult *collectionlists1 = [PHCollectionList fetchCollectionListsWithType:PHCollectionListTypeMomentList subtype:PHCollectionListSubtypeAny options:nil];    //NSArray *allLists = @[fetchResult, collectionlists, collectionlists1];    //NSArray *allLists = @[fetchResult];    NSArray *allLists = @[collectionlists1];//    NSArray *allLists = @[fetchResult];    for (PHFetchResult *fetchResultList in allLists) {        [fetchResultList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {            if ([obj isKindOfClass:[PHCollectionList class]]) {                PHCollectionList *collectionList = (PHCollectionList *)obj;                [self phassetWithPHCollectionList:collectionList];            }        }];    }//    [fetchResults enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {//        if ([obj isKindOfClass:[PHCollectionList class]]) {//            PHCollectionList *collectionList = (PHCollectionList *)obj;//            [self phassetWithPHCollectionList:collectionList];//        }//    }];}- (void)phassetWithPHCollectionList:(PHCollectionList *)collectionList{    PHFetchResult<PHCollection *> *collections = [PHCollectionList fetchCollectionsInCollectionList:collectionList options:nil];    NSMutableArray<AssetsGroupModel *> *arrM = [NSMutableArray arrayWithCapacity:0];    for (id obj in collections) {        if ([obj isKindOfClass:[PHAssetCollection class]]) {            PHAssetCollection *assetCollection = (PHAssetCollection *)obj;            AssetsGroupModel *groupModel = [AssetsGroupModel new];            groupModel.groupName = assetCollection.localizedTitle;            NSLog(@"相簿名:%@", assetCollection.localizedTitle);            PHFetchResult<PHAsset *> *assetsFetchResults = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];            [assetsFetchResults enumerateObjectsUsingBlock:^(PHAsset * _Nonnull asset, NSUInteger idx, BOOL * _Nonnull stop) {                // Photos library                UIScreen *screen = [UIScreen mainScreen];                CGFloat scale = screen.scale;                // Sizing is very rough... more thought required in a real implementation                //CGSize size = CGSizeMake(_asset.pixelWidth, _asset.pixelHeight);                CGFloat imageSize = MAX(screen.bounds.size.width, screen.bounds.size.height) * 1.5;                CGSize imageTargetSize = CGSizeMake(imageSize * scale, imageSize * scale);                AssetModel *model = [AssetModel assetWithPHAsset:asset targetSize:imageTargetSize];                [groupModel.assetsArrM addObject:model];            }];            [arrM addObject:groupModel];        }    }    //NSLog(@"arrM is %@", arrM);}
原创粉丝点击