ALAssetsLibrary is too slow - Objective-C

我与影子孤独终老i 提交于 2019-12-03 09:03:23
Shamsudheen TK

The ALAssetsLibrary library will run on a separate thread. So it may take time to communicate with the UI related and other stuff.

So use -performSelectorOnMainThread:withObject:waitUntilDone: inside the ALAssetsLibrary block.

Change your code as below

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *needToStop) {
            NSLog(@"%d",index);
            UIImage *image = [UIImage imageWithCGImage:result.defaultRepresentation.fullScreenImage];
            [self performSelectorOnMainThread:@selector(usePhotolibraryimage:) withObject:image waitUntilDone:NO];
        }];
    }

    failureBlock:^(NSError *error) {
           NSLog(@"%@",error.description);
    }];

- (void)usePhotolibraryimage:(UiImage *)myImage{

    //Do your all UI related and all stuff here
}

Note:Look on this issue too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!