Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

nil image from UIImagePicker url #693

Open
xinsight opened this issue Jul 30, 2020 · 2 comments
Open

nil image from UIImagePicker url #693

xinsight opened this issue Jul 30, 2020 · 2 comments

Comments

@xinsight
Copy link

When selecting and sending an image, I'm finding that I'm unable to load the selected image (into NSData). The dict returned by the UIImagePIcker contains all the expected keys/values, but using [NSData dataWithContentsOfFile:imageLocalURL.path]; only results in nil.

I've added the plist value to access the photo library: NSPhotoLibraryUsageDescription

Does this image picker code need to be updated to use PhotoKit?

// from: MXKRoomInputToolbarView.m
NSURL *imageLocalURL = [info objectForKey:UIImagePickerControllerReferenceURL];
if (imageLocalURL)
{
   CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[imageLocalURL.path pathExtension] , NULL);
   NSString *mimetype = (__bridge_transfer NSString *) UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
   CFRelease(uti);
   
   NSData *imageData = [NSData dataWithContentsOfFile:imageLocalURL.path]; // nil!
@xinsight
Copy link
Author

I've confirmed that it works if you use PhotoKit. For example:

PHImageManager *manager = [PHImageManager defaultManager];
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = YES;
requestOptions.version = PHImageRequestOptionsVersionCurrent;
[manager requestImageDataForAsset: asset
                          options: requestOptions
                    resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
                                     [self sendSelectedImage:imageData withMimeType:mimeType andCompressionMode:MXKRoomInputToolbarCompressionModePrompt isPhotoLibraryAsset:YES];
                                  }];

Anyone interested in a PR for this?

@11health-joshua
Copy link

11health-joshua commented Oct 16, 2020

I am seeing this issue as well. I would love to see a fix for this. In the meantime I will have to override this in a custom toolbar as a work around. Let you know how that goes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants