How to get all photos moment wise using ALAssetLibrary in ios7?

后端 未结 2 1276
无人共我
无人共我 2021-01-25 14:13

I have problem to get photos in moment wise like apple iphone have in ios8. I have implemented for ios8 using PHAsset and Photos.framework. Now, when i run same code in ios7 dev

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-25 14:53

    I found its solutions my self.

    + (ALAssetsLibrary *)defaultAssetsLibrary {
        static dispatch_once_t pred = 0;
        static ALAssetsLibrary *library = nil;
        dispatch_once(&pred, ^{
            library = [[ALAssetsLibrary alloc] init];
        });
        return library;
    }
    
    -(void)loadAssets{
        NSMutableArray *unSortArray = [[NSMutableArray alloc] init];
        ALAssetsLibrary *library = [MomentsVCTR defaultAssetsLibrary];
        [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
            if (group == nil) {
                NSLog(@"Done!");
                [self manageLocalAssets:unSortArray];
            }
            [group setAssetsFilter:[ALAssetsFilter allAssets]];
            [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
                if (alAsset) {
                    [unSortArray addObject:alAsset];
                }
    
            }];
        } failureBlock: ^(NSError *error) {
            NSLog(@"No groups: %@",error);
        }];
    }
    
    -(void)manageLocalAssets:(NSMutableArray*)unSortArray{
        NSMutableArray *_resultArray = [[NSMutableArray alloc] init];
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"dd-MMM-yyyy"];
        NSLog(@"in loadassets");
        NSSortDescriptor *descriptor=[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
        NSArray *descriptors=[NSArray arrayWithObject: descriptor];
        NSArray *reverseOrder=[unSortArray sortedArrayUsingDescriptors:descriptors];
    
        for (int k=0; k

提交回复
热议问题