我有以下函数,它使用 new 加载图像PHPickerViewController
:
- (void) picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results
{
PHPickerResult *result = [results firstObject];
if (result)
{
[result.itemProvider loadObjectOfClass:[UIImage class] completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object, NSError * _Nullable error)
{
dispatch_async(dispatch_get_main_queue(),
^{
if (!error)
{
[self pickerControllerDidFinishPickingWithImage:(UIImage *)object];
}
else
{
[self pickerControllerDidFinishWithError];
}
});
}];
}
}
我想避免使用loadObjectOfClass
,因为我不希望图像异步加载。所以我选择loadItemForTypeIdentifier
改用并做了以下事情:
[result.itemProvider loadItemForTypeIdentifier:@"public.image" options:nil completionHandler:^(__kindof id<NSItemProviderReading> _Nullable object, NSError * _Nullable error)
{
dispatch_async(dispatch_get_main_queue(),
^{
if (!error)
{
[self pickerControllerDidFinishPickingWithImage:(UIImage *)object];
}
else
{
[self pickerControllerDidFinishWithError];
}
});
}];
但是,当我运行此代码时,我得到:
ncaught 异常“NSInvalidArgumentException”,原因:“-[NSURL imageOrientation]:无法识别的选择器发送到实例 0x600001ce5920”以 NSException 类型的未捕获异常终止
我对积木不是很好,这是我第一次使用 aUTI
所以我想知道,我在这里做错了什么?甚至有可能完成我想要完成的事情,即UIImage
使用拉出loadItemForTypeIdentifier
吗?我的语法错了吗?