用于打开菜单的UIDocumentInteractionController - 不起作用 [英] UIDocumentInteractionController for Open In menu - Doesn't Work

查看:1378
本文介绍了用于打开菜单的UIDocumentInteractionController - 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个UIDocumentInteractionController来将文件发送到其他应用程序。该文件是.txt文件。

I implemented a UIDocumentInteractionController to send files to other apps. The file is a .txt file.

以下是代码:

UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init];
[interactionController setURL:[NSURL fileURLWithPath:filePath]];
[interactionController setUTI:@"public.text"];
[interactionController setDelegate:self];
[interactionController presentOpenInMenuFromBarButtonItem:actionBarButtonItem animated:YES];

菜单打开正常,可以显示像Pages,Dropbox等应用程序。但当我点击其中一个时,Open In菜单会解散并且不执行任何操作(文件未发送且目标应用程序永远不会打开。

The menu opens fine, showing apps like Pages, Dropbox, etc. as I expect. But when I tap one of them, the Open In menu dismisses and no action is performed (the file is not sent and the target application never opens.

我尝试实施委托方法 documentInteractionController:canPerformAction: documentInteractionController:performAction:用于触发copy:和print:调用使用选项菜单(而不是菜单中的打开)并且只提供了一个菜单,其中只列出了页面,但仍然无效。

I tried implementing the delegate methods documentInteractionController:canPerformAction: and documentInteractionController:performAction: for triggering copy: and print: calls using the options menu (as opposed to the open in menu) and that pulled up a menu with only Pages listed, but that still did not work.

如何解决这个问题?

推荐答案

我找到了答案,它是内存管理。我创建了UIDocumentInteractionController然后呈现它,但我没有它作为一个实例变量.ARR在它有机会做任何事情之前解除它。这包括将文档发送到外部应用程序。

I found the answer, and it's memory management. I create the UIDocumentInteractionController and then present it, but I don't have it as an instance variable. ARC deallocates it before it has the opportunity to do anything. This includes sending the document to the external app.

这个bug没有出现在iPhone上,但是在iPad上它会出错,因为popover archit结论有点不同,它最终试图在它被解除分配时绘制它。这就是提醒我这个错误的原因。

This bug didn't appear on the iPhone, but on the iPad it gives an error because the popover architecture works a bit differently and it ends up trying to draw it when it's deallocated. That's what alerted me to the bug.

这篇关于用于打开菜单的UIDocumentInteractionController - 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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