UIDocumentInteractionController在iBooks中打开pdf时崩溃 [英] UIDocumentInteractionController opening pdf in iBooks crashes

查看:161
本文介绍了UIDocumentInteractionController在iBooks中打开pdf时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要通过我的应用程序在iBooks中打开的测试PDF文件.我将其保存在temp目录中,并使用以下代码将其加载到iBooks:

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];

菜单弹出很好,但是当我点击iBooks按钮时,应用崩溃并挂起了我的Xcode.

The menu pops up just fine but when I tap the iBooks button the app crashes and hangs my Xcode.

我在NSLog输出中获得的文件路径如下:

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!

推荐答案

使用UIDocumentInteractionController要求您保留一个引用,直到完成为止.这意味着您应该使用实例变量,而不是局部变量.实现适当的委托方法,以便在完成控制器后可以重置ivar.

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).

这篇关于UIDocumentInteractionController在iBooks中打开pdf时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆