简体   繁体   English

目标C:在iBooks上打开PDF文件

[英]Objective C: Opening A PDF File on iBooks

I am downloading a PDF file from an online server and save it to my the App's Sandbox then view it in iBooks. 我正在从在线服务器下载PDF文件,并将其保存到应用程序的沙箱中,然后在iBooks中查看。

The iBooks viewing is what i am struggling now. 我现在正在努力查看iBooks。 I tried this code: 我尝试了这段代码:

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];

    docController.delegate = self;

    [docController presentOpenInMenuFromRect:savePDF.frame inView:self.view animated:YES];
    [docController dismissMenuAnimated:YES];

Still gor no chance, It is running but the popover is being dismissed right away after it was presented. 仍然没有机会,它正在运行,但是弹出窗口在显示后立即被撤消。 But when I deleted [docController dismissMenuAnimated:YES]; 但是当我删除[docController dismissMenuAnimated:YES]; it gives me an error saying '-[UIPopoverController dealloc] reached while popover is still visible.' 它给我一个错误,说'-[UIPopoverController dealloc] reached while popover is still visible.'

What could be the problem? 可能是什么问题呢?

The problem is that your UIDocumentInteractionController is being released right after being presented, due to the variable docController no longer being in scope. 问题在于,由于变量docController不再在作用域中,因此您的UIDocumentInteractionController在发布后UIDocumentInteractionController被释放。

To prevent that, you should create a strong property or an instance variable and store your UIDocumentInteractionController in there. 为了避免这种情况,您应该创建一个strong属性或实例变量,然后将UIDocumentInteractionController存储在其中。 That way, the UIDocumentInteractionController will stick around until you release the object controlling it, which should be long enough for the user to make a selection... 这样, UIDocumentInteractionController会一直存在,直到您释放对其进行控制的对象为止,该对象应该足够长以便用户进行选择...

I tried everything again and again but finally got the [UIPopoverController dealloc] reached while popover is still visible error to go away and all is working by doing this: 我一遍又一遍地尝试了一切,但最终都达到了[UIPopoverController dealloc],而弹出窗口仍然是可见的错误消失了,一切都通过以下方式进行:

Go to your Project Build Phases --> then Compile Sources --> choose the .m that you are having the issue with and double click the Compiler Flag and add -fobjc-arc then clean and build your app. 转到项目构建阶段->然后选择编译源->选择您遇到问题的.m,然后双击编译器标志并添加-fobjc-arc,然后清理并构建您的应用程序。

Again this wont work for everyone and may not be the right answer but it may also help a few others having the same issue I had. 同样,这对每个人都行不通,也许不是正确的答案,但它也可能会帮助其他一些遇到与我相同的问题。

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

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