UIDocumentInteractionController opening pdf in iBooks crashes

[亡魂溺海] 提交于 2019-12-23 03:11:51

问题


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!


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!