22

I implemented a UIDocumentInteractionController to send files to other apps. The file is a .txt file.

Here's the code:

UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init];
[interactionController setURL:[NSURL fileURLWithPath:filePath]];
[interactionController setUTI:@"public.text"];
[interactionController setDelegate:self];
[interactionController presentOpenInMenuFromBarButtonItem:actionBarButtonItem animated:YES];

The menu opens fine, showing apps like Pages, Dropbox, etc. as I expect. But when I tap one of them, the Open In menu dismisses and no action is performed (the file is not sent and the target application never opens.

I tried implementing the delegate methods documentInteractionController:canPerformAction: and documentInteractionController:performAction: for triggering copy: and print: calls using the options menu (as opposed to the open in menu) and that pulled up a menu with only Pages listed, but that still did not work.

How might this be resolved?

3 Answers 3

51

I found the answer, and it's memory management. I create the UIDocumentInteractionController and then present it, but I don't have it as an instance variable. ARC deallocates it before it has the opportunity to do anything. This includes sending the document to the external app.

This bug didn't appear on the iPhone, but on the iPad it gives an error because the popover architecture works a bit differently and it ends up trying to draw it when it's deallocated. That's what alerted me to the bug.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks! I have been searching on stack for a long time and I finally found this answer works for me.
This is the answer for ARC projects. You have to declare a property for the UIDocumentInteractionController: @property(nonatomic, strong)UIDocumentInteractionController * docController;
thnx. have spent a couple of hours. but forget about arc. thnx a lot one more time.
16

This bug also appears on iPhone/iPod. Just set:

@property (nonatomic, retain) UIDocumentInteractionController *docController;

and it will be retain and the document passed to the new application.

Comments

-4

it's enough to add the following code:

[interactionController retain];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.