UIDocumentInteractionController doesn't open the app (didEndSendingToApplication: never called)
Asked Answered
D

3

5

I have a UIDocumentInteractionController instance (that DOES have a strong reference in my class, I am aware of the memory issues about it) and I want to send a photo file to Instagram.

I saved the file using the ig extension (tried igo as well) and I am presenting the controller. Instagram is displayed on the list. I tap Instagram, and nothing happens.

NSURL *imageFile = [NSURL fileURLWithPath:path];
interactionController = [UIDocumentInteractionController interactionControllerWithURL:imageFile];
interactionController.UTI = @"com.instagram.photo";
interactionController.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"];
interactionController.delegate = self;
[interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];

To investigate further, I've set my calling class as a delegate and implemented the willBeginSendingToApplication: and didEndSendingToApplication: methods. Interestingly, I've realized that willBeginSendingToApplication: does get called, but didEndSendingToApplication: does not. I've tried changing my file extensions, changing UTI to com.instagram.exclusivegram, checking if the file URL is correct etc. but none of them seem to work. No error, nothing in the console or anything. The interaction controller closes, my app keeps working as it was working before, just nothing happens. I've read that there can be some issues on iOS 6, but my app is an iOS 6 app, so I can't test it on iOS < 6. The only thing that is close to my problem that I've found is UIDocumentInteractionController, No File Extension but UTI but it dives too much into the low level bits, nor I have a non-ARC code.

What could be the cause of the problem?

Desorb answered 14/5, 2013 at 12:32 Comment(1)
Did you try testing on a physical device? Simulator didn't work for me, but testing on a physical device works.Ainu
D
1

After a long while, I've found out that the file was not saved correctly, and didn't exist. iOS wasn't throwing out any sort of an error, failing silently. I've corrected the code about generating the file, and when the file was there, the controller appeared. Maybe Apple should add some assertion/exception mechanism for handling non-existent files in document interaction controller.

Desorb answered 6/8, 2013 at 22:21 Comment(0)
T
6

This can happen if the file doesn't exist, but also if you haven't constructed the file URL correctly. This plagued me for a while.

Make sure you construct your file URL like this:

NSURL *pagesURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MyGreatPDF.pdf" ofType:nil]];

or this:

NSURL *pagesURL = [[NSURL fileURLWithPath:@"MyGreatPDF.pdf"] URLByResolvingSymlinksInPath];

and not like this:

NSURL *pagesURL = [NSURL fileURLWithPath:@"MyGreatPDF.pdf"];

The latter still forms a valid URL, but it gets a "private" prefix, i.e. file:///private/var/mobile/Applications/00000000-0000-0000-0000-000000000000/MyGreatApp.app/MyGreatPDF.pdf rather than file:///var/mobile/Applications/00000000-0000-0000-0000-000000000000/MyGreatApp.app/MyGreatPDF.pdf

See https://developer.apple.com/documentation/foundation/nsurl/1415965-urlbyresolvingsymlinksinpath?language=objc for info on the stripping of /private from the generated URL.

Trevor answered 20/3, 2014 at 8:59 Comment(2)
My Delegate Methods are not calling when i press mail from document interaction controller, I have try your answer alsoMogador
@Mogador Another gotcha is if your UIDocumentInteractionControllerDelegate instance is deallocated prematurely. Make sure you're retaining a reference to it (by putting it into a instance property, or adding __retain to it if stored in a static variable).Trevor
D
1

After a long while, I've found out that the file was not saved correctly, and didn't exist. iOS wasn't throwing out any sort of an error, failing silently. I've corrected the code about generating the file, and when the file was there, the controller appeared. Maybe Apple should add some assertion/exception mechanism for handling non-existent files in document interaction controller.

Desorb answered 6/8, 2013 at 22:21 Comment(0)
I
0

This may also caused by the file name's extension.

If the target app declare it only support file with png extension in Info.plist -> Exported Type UTIs -> Equivalent Types -> public.filename-extension, and you send a file with jpg extension, the target app won't open as well.

Irresolution answered 11/4, 2016 at 2:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.