gpt4 book ai didi

ios - [PHCollectionList canContainCustomKeyAssets] : unrecognized selector sent to instance

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:04 26 4
gpt4 key购买 nike

在最新版本的 iOS(iOS 9.2 和 iOS 9.3)上,获取 PHAssets 现在崩溃了。它以前工作正常。

我得到的错误是:

[PHCollectionList canContainCustomKeyAssets]: unrecognized selector sent to instance Terminating app due to uncaught exception 'NSInvalidArgumentException'

抛出异常的行是:

            PHFetchResult *fetchImage = [PHAsset fetchKeyAssetsInAssetCollection:(PHAssetCollection*)collection options:fetchOptions];

更多代码,供引用:

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();
}
}];
}

最佳答案

这个问题其实出在这里:

PHCollection *collection = fetchResult[indexPath.row];

然后在这里:

PHAsset *asset = [fetchImage firstObject];

您正在使用 PHCollection 获取集合,然后假设所有 Assets 都是 PHAssets 而没有正确检查是否是这种情况。

实际上,PHCollection 有 two possible subclasses : PHAssetPHCollectionList,而 PHCollectionList 是这里引发错误的原因。

PHCollection *collection = fetchResult[indexPath.row]; 之后包装代码并检查 PHAsset,它应该可以解决问题:

if ([collection isKindOfClass:[PHAssetCollection class]]) {
//code
}

关于ios - [PHCollectionList canContainCustomKeyAssets] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36619351/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com