Reputation: 151
I have the following function which loads an image using the 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];
}
});
}];
}
}
I want to avoid using loadObjectOfClass
because I don't want the image to load asynchronously. So I opted to use loadItemForTypeIdentifier
instead and did the following:
[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];
}
});
}];
However, when I run this code I am getting:
ncaught exception 'NSInvalidArgumentException', reason: '-[NSURL imageOrientation]: unrecognized selector sent to instance 0x600001ce5920' terminating with uncaught exception of type NSException
I am not that great with blocks and this is my first time using a UTI
so I'm wondering, what am I doing wrong here? Is it even possible to accomplish what I'm trying to accomplish, i.e. pull a UIImage
out using loadItemForTypeIdentifier
? Am I getting the syntax wrong?
Upvotes: 0
Views: 579