【问题标题】:UIActivityViewController not showing "Open in iBooks" optionUIActivityViewController 未显示“在 iBooks 中打开”选项
【发布时间】:2013-04-15 18:46:18
【问题描述】:

我的应用程序有问题。得到一些统计数据后,我生成了一个 PDF 文件,我想显示一个 UIActivityViewController,主要包含“在 iBooks 中打开”和“通过邮件发送”选项(其他类似“在 Dropbox 中打开”会很棒)。

问题是,在尝试使用 UIActivityViewController 之前,我使用的是 UIDocumentInteractionController,代码如下:

self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[_docController presentOpenInMenuFromRect:_openInIBooksButton.bounds inView:self.openInIBooksButton animated:YES];

其中 url 是 /Documents/../statistics.pdf 之类的路径。它起作用了,它显示了一个弹出窗口,其中的按钮在 iBooks 中打开并在 Dropbox 中打开,但不是通过邮件发送。现在我用以下代码对其进行了更改:

NSArray* itemsToShare = [NSArray arrayWithObjects:pdfData, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard]; //or whichever you don't need
[self presentViewController:activityVC animated:YES completion:nil];

其中 pdfData 是一个 NSData 对象。它也可以工作,但现在它显示了通过电子邮件发送的选项,而不是 iBooks 选项。我要疯了,因为我找不到这种行为的原因,我需要 iBooks 和 Mail 这两个选项。

我不知道这是否与 UIDocumentInteractionController 的路径以 .pdf 结尾并且 UIActivityViewController 只有一个 NSData 对象这一事实有关。但我找不到解决方案。

以前有人发现过这个问题吗?

非常感谢。

【问题讨论】:

  • 你试过 UIDocumentInteractionController 的presentOptionsMenuFromBarButtonItem 了吗? - 我认为 UIActivityViewController 的 initWithActivityItems 参数也接受数组中的 NSURL 项目,这可能会有所帮助。
  • 感谢您的回复,但是如果您将 url 放入数组中,它只会显示通过邮件发送和在 twitter 上发布选项,如果您点击通过邮件发送,它会打开邮件编辑器包含 url,但不附加文件的文本..
  • 好吧,这只是一个想法! presentOptionsMenuFromBarButtonItem 呢?

标签: objective-c email pdf ibooks uiactivityviewcontroller


【解决方案1】:

当您使用presentOpenInMenuFromRect:inView:animated: 时,您只会获得可以使用给定文件的应用列表。

您想要使用的是presentOptionsMenuFromRect:inView:animated:,它为您提供了您正在寻找的选项。

【讨论】:

  • 非常感谢,但是如果您在邮件中打开附加的 PDF,预览它并点击按钮共享,会显示一个弹出框,其中包含在 iBooks 中打开并通过邮件发送的选项,怎么可能?
  • 不要使用presentOpenInMenuFromRect:方法,而是使用UIDocumentInteractionController的presentOpenInMenuFromRect:`方法。
  • 抱歉,您也说了同样的话...?关于替换 presentOpenInMenuFromRect: 的方法是什么?
  • 抱歉(复制/粘贴错误)。将您对presentOpenInMenuFromRect:inView:animated: 的呼叫替换为presentOptionsMenuFromRect:inView:animated:
  • @diegomen 所以你实际上没有使用 UIActivityViewController?
猜你喜欢
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
  • 2017-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多