1

In my app I use UIDocumentInteractionController to open a pdf document into acrobat reader (or any others viewers) but since iOS6 it doesn't work anymore.

I have try a lot of things, the last is from here :

UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc]init];
docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:documentsDirectory]];
docControler.UTI = @"com.adobe.pdf";
docController.delegate = self;
CGrect navRect = self.view.frame;
[docController presentOpenInMenuFromRect:navRect inView:self.view animated:YES];

When this code is running, my app totally freeze. I have try with "presentOpenInMenuFromBarButtonItem" but I have the same issue.

Community
  • 1
  • 1
Alex R.
  • 861
  • 1
  • 13
  • 28

2 Answers2

4

assign the controller to a strongly referenced property:

@property (nonatomic, strong) UIDocumentInteractionController *docController;
dalton_c
  • 6,876
  • 1
  • 33
  • 42
  • Unfortunately it doesn't work. It seem that a popup is open and go immediately at the left top corner of my iPhone before to stuck my app... Weird – Alex R. Apr 08 '13 at 14:33
  • Instead of specifying a rect, try passing `CGRectZero`. – dalton_c Apr 08 '13 at 14:39
  • Same problem but I have bypassed that issues by opening my pdf into an UIWebView. Thanks for your help – Alex R. Apr 08 '13 at 15:03
2

I've used UIDocumentInteractionController successfully in iOS 6. Sample code:

self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:myPDFPath]];
[self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.actionButton animated:YES];

You need to retain a reference to the UIDocumentInteractionController or it will be released before it's job is done.

Also, it looks like you're using the path of the documents folder, not the path to a particular file. I don't think this will work - pass the path to a specific file.

stevex
  • 5,589
  • 37
  • 52
  • I use the path of my pdf document, it's just a bad named variable. Your answer doesn't work but it add in my log console the following : [ViewControllerApps setDocController:] unrecognized selector sent to instance 0x763000 – Alex R. Apr 08 '13 at 14:36
  • I had a similar problem about a local PDF document that i couldn't open with UIDocumentInteractionController by selecting "Adobe Reader" program. The fact i didn't have declared a property into my UIViewController to retain the UIDocumentInteractionController was the trouble. Moreover, another clue of the missing retain is the "willBeginSendingToApplication" method isn't triggered when you select an external program to open the document. – Klaonis Dec 05 '18 at 09:39