3

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?

  • Are you storing the whole path ? Can you show how you created `filePath` ? – Midhun MP Sep 28 '15 at 10:52
  • It's rather complicated, because I keep many directories in my Documents (I made helper methods), but the filePath is correct: I am able succesfully perform `UIImage imageWithContentsOfFile` with it. – user3087425 Sep 28 '15 at 10:54
  • Add the code where you read "(null) object instead of the Image" from `UIDocumentInteractionController`. – A-Live Sep 28 '15 at 10:59
  • It's a log message appearing after picking 'Assign to contact' option. `Couldn't get file size for (null): (null)` . The image doesn't appear during this operation. – user3087425 Sep 28 '15 at 11:10
  • Did you get the solution for it? – Himanshu Joshi Nov 19 '15 at 07:04

1 Answers1

3

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;
Community
  • 1
  • 1
drstupid
  • 423
  • 5
  • 8