Das Abrufen von PHAssets stürzt jetzt bei den neuesten Versionen von iOS ab (iOS 9.2 und iOS 9.3). Es hat vorher gut funktioniert.[PHCollectionList canContainCustomKeyAssets]: unerkannter Selektor an Instanz gesendet
Der Fehler Ich erhalte ist:
[PHCollectionList canContainCustomKeyAssets]: Unbekannter Selektor an Instanz gesendet App beenden aufgrund nicht abgefangene Ausnahme 'NSInvalidArgumentException'
Die Linie, die Ausnahme zu werfen ist:
PHFetchResult *fetchImage = [PHAsset fetchKeyAssetsInAssetCollection:(PHAssetCollection*)collection options:fetchOptions];
Hier ist mehr Code, als Referenz:
Class PHPhotoLibrary_class = NSClassFromString(@"PHPhotoLibrary");
if (PHPhotoLibrary_class) {
PHFetchResult *fetchResult = self.collectionsFetchResults[indexPath.section];
PHCollection *collection = fetchResult[indexPath.row];
cell.textLabel.text = collection.localizedTitle;
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *fetchImage = [PHAsset fetchKeyAssetsInAssetCollection:(PHAssetCollection*)collection options:fetchOptions];
PHAsset *asset = [fetchImage firstObject];
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.resizeMode = PHImageRequestOptionsResizeModeExact;
CGFloat scale = [UIScreen mainScreen].scale;
CGFloat dimension = 90.0;
CGSize size = CGSizeMake(dimension*scale, dimension*scale);
[[PHImageManager defaultManager] requestImageForAsset:asset
targetSize:size
contentMode:PHImageContentModeAspectFill
options:options
resultHandler:^(UIImage *result, NSDictionary *info) {
if (result) {
CGSize itemSize = CGSizeMake(60, 60);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, 2);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[result drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else{
UIImage *placeholder = [UIImage imageNamed:@"image-placeholder.jpg"];
CGSize itemSize = CGSizeMake(60, 60);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, 2);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[placeholder drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}];
}