I'm trying to grab all of the users PHAsset
with PHAssetMediaTypeImage
and then iterate through them, getting the corresponding UIImages
one at a time. I have about 2k photos on my iPhone 5 and this code crashes after iterating through 587 of them.
PHFetchResult *fr = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
PHImageManager *manager = [PHImageManager defaultManager];
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.synchronous = YES;
__block int i = 0;
for (PHAsset *result in fr)
{
[manager requestImageForAsset:result targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *image, NSDictionary *info) {
NSLog(@"%d", i);
i++;
}];
}
The exception reads EXC_BAD_ACCESS (code=1, address=0x0). Any help pointing me in the right direction on this will be enormously appreciated.
The problem for me was found in the this line of code
The parameter, targetSize was passed the value of PHImageManagerMaximumSize which was the culprit. I changed it to
lCgSize
,lCgSize = CGSizeMake(105, 105);
resolved the issue.According to the documentation PHImageManagerMaximumSize
So, this explains the problem. I believe if it was a single image, it should not be a problem but if it was many images, the device would run out of memory.