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?