Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDocumentInteractionController: (null) image

I'm downloading an image from API and saving it to a directory on the device. Then I'm trying to use UIDocumentInteractionController on it, passing on the local path of image I just saved.

NSURL *url = [NSURL fileURLWithPath: filePath];
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: url];
interactionController.delegate = self;
CGRect rect = CGRectMake(0, 0, 300, 300);
[interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];

When I compare two NSString by logging, this is what I get:

  • [url absoluteString]

    file:///var/mobile/Containers/Data/Application/1121F345-0BCA-4624-8A72-F4CE0D39EAE5/Documents/complaint/1443432747ea3dc39ca0b2f6b5f17abddec1f0e9a439955.png

  • filePath

    /var/mobile/Containers/Data/Application/1121F345-0BCA-4624-8A72-F4CE0D39EAE5/Documents/complaint/1443432747ea3dc39ca0b2f6b5f17abddec1f0e9a439955.png

As you can tell, the path is indentical, apart from file:// at the beginning or url string. The image isn't corrupted, yet in every action picked from UIDocumentInteractionController (saving image, assigning it to contact, etc) there is a (null) object instead of the Image. What am I doing wrong?

EDIT:

If I use

[interactionController presentPreviewAnimated:YES];

instead of

[interactionController presentOptionsMenuFromRect:rect inView:self.view animated:YES];

And provide delegate method documentInteractionControllerViewControllerForPreview: image displays and all actions work. Why does it work when used with preview, but not without it?

like image 268
user3087425 Avatar asked Oct 15 '25 01:10

user3087425


1 Answers

I found my answer in this question.

Basically the UIDocumentInteractionController was deallocated (ARC) before the selected action could be processed. Make sure it is retained, I did that by creating a strong property for it (strong is default for the example below).

@property (nonatomic) UIDocumentInteractionController *interactionController;
like image 158
drstupid Avatar answered Oct 17 '25 16:10

drstupid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!