iOS PHCollectionList详解

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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值