简体   繁体   English

UIDocumentInteractionController在iBooks中打开pdf时崩溃

[英]UIDocumentInteractionController opening pdf in iBooks crashes

I have a test PDF file that I want to open in iBooks through my app. 我有一个要通过我的应用程序在iBooks中打开的测试PDF文件。 I saved it in my temp directory and I use this code to load it to iBooks: 我将其保存在temp目录中,并使用以下代码将其加载到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. 菜单会弹出,但是当我点击iBooks按钮时,应用程序崩溃并挂起了Xcode。

The path to the file I get in my NSLog output is like this: 我在NSLog输出中获得的文件路径如下所示:

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. 使用UIDocumentInteractionController要求您保留一个引用,直到完成为止。 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. 实现适当的委托方法,以便在完成控制器后可以重置ivar。

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). 您很可能会看到一条消息正在发送到已释放对象(您的控制器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM