+-
IOS 相册里图片很多 比如2000多张 内存飙升到1g多 崩溃了。
There are a lot of pictures in the IOS photo album. For example, more than 2000 pieces of memory soared to more than 1G and crashed
2020-11-10 18:25:42.921000+0800 ClearPhotoDemo[2855:107408] 原图大小为:8.33M,而缩率图尺寸为:{640, 360}
2020-11-10 18:25:42.941357+0800 ClearPhotoDemo[2855:107869] [GatekeeperXPC] Connection to assetsd was interrupted - assetsd exited, died, or closed the photo library
2020-11-10 18:25:42.946583+0800 ClearPhotoDemo[2855:107408] 原图大小为:10.24M,而缩率图尺寸为:{640, 360}
// 如果已经授权, 获取相簿中的所有PHAsset对象
- (void)getAllAsset
{
// 获取所有资源的集合,并按资源的创建时间排序,这样就可以通过和上一张图片判断日期来分组了
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *result = [PHAsset fetchAssetsWithOptions:options];
self.assetArray = result;
// 最初从第一张图片,数组中位置0的图片开始获取
[self requestImageWithIndex:0];
}
// 获取压缩大小后的图片,即缩略图
[imageManager requestImageForAsset:asset targetSize:CGSizeMake(125, 125) contentMode:PHImageContentModeDefault options:self.imageRequestOptions resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
// 获取原图(原图大小)
@autoreleasepool {
[imageManager requestImageDataAndOrientationForAsset:self.assetArray[index] options:self.imageSizeRequestOptions resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, CGImagePropertyOrientation orientation, NSDictionary * _Nullable info) {
// 处理图片,分别传入缩略图和原图
[weakSelf dealImageWithIndex:index exactImage:result originImageData:imageData];
}];
}
}];