I have a test PDF file that I want to open in iBooks through my app. I saved it in my temp directory and I use this code to load it to iBooks:
NSURL *targetURL = [NSURL fileURLWithPath:tempFullPath];
NSLog(@"Path is %@", tempFullPath);
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:targetURL];
controller.delegate = self;
controller.UTI = @"com.adobe.pdf";
[controller presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
The menu pops up just fine but when I tap the iBooks button the app crashes and hangs my Xcode.
The path to the file I get in my NSLog output is like this:
Path is /private/var/mobile/Applications/65EC4182-A79B-431C-9E74-BD72D91A31AB/tmp/TestFile.pdf
What am I doing wrong? Thanks in advance!
The use of a UIDocumentInteractionController
requires that you keep a reference around until it is complete. This means you should use an instance variable, not a local variable. Implement the proper delegate methods so you can reset the ivar when you are done with the controller.
Enabling zombies will help debug such an issue. Most likely you will see that a message is being sent to a deallocated object (your controller).
来源:https://stackoverflow.com/questions/15664058/uidocumentinteractioncontroller-opening-pdf-in-ibooks-crashes