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

StackOverflow https://stackoverflow.com/questions/16543232

  •  29-05-2022
  •  | 
  •  

Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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]];

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top