ios - 点击 `Add Tags` 选项会关闭 UIDocumentInteractionController 突然启动的底层模态视图

标签 ios objective-c swift

我正在使用 UIDocumentationInteractionController显示 PDF 文档的共享选项。 (见下图)除了 Add Tags 之外,一切都按预期工作。选项

document interaction controller screenshot

点击它会立即关闭 Controller 模态视图,而不是显示另一个用于选择标签的弹出窗口。

当我执行上述工作流程时,我也会在控制台上看到此错误。

DocInteractionTest[7132:5381612] Warning: Attempt to present <_UIRemoteViewController: 0x118003a00> on <UIActivityContentViewController: 0x116000000> whose view is not in the window hierarchy!

我相信这种情况发生在模态视图在 Add Tags 之前被解除时。 modal 被添加到 View 层次结构堆栈中。但是,我无法理解为什么会这样?过去有没有其他人也看到过类似的问题?

我也可以隐藏该选项(添加标签),但我怀疑这是可能的,因为 Apple 没有公开任何 API 来执行此操作。

这是我必须启动文档交互 Controller 模态视图的一些示例代码(我只包含了相关部分)
@interface ViewController () < UIDocumentInteractionControllerDelegate>

@property (nonatomic, strong) UIDocumentInteractionController *shareDocumentInteractionController;

@end

@implementation ViewController

- (void) showShareMenu:(id) sender {
    NSURL* url = [NSURL fileURLWithPath:[self getPDFPath]]; // pdf document path on disk
    self.shareDocumentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
    self.shareDocumentInteractionController.delegate = self;
    self.shareDocumentInteractionController.UTI = @"com.adobe.pdf";
    [self.shareDocumentInteractionController presentOpenInMenuFromBarButtonItem:sender animated:YES];
}

@end

最佳答案

It would also be fine for me to hide that option (Add Tags) but I doubt that is possible since Apple doesn't expose any APIs to do this.



关于我在问题中的上述评论,我碰巧偶然发现了 this苹果帖子讨论了应将应用程序文档保存在何处的最佳实践。阅读这篇文章让我意识到我们可以根据保存 PDF 文档的位置显示不同的模式菜单,并在 UIDocumentInteractionController 中引用它。 .

当我发布上面的示例代码时,我将 PDF 文档保存在 NSDocumentDirectory 中。 .但是,将其更改为 NSCachesDirectory向我展示了一个不同的菜单(没有我想要的 Show Tags 选项)。此外,对于我的特定用例,将 PDF 文档临时保存在 Caches 目录中非常完美。
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

新模式菜单:

enter image description here

如果有人仍然能够回答模态消失的原因,那就太好了,但我可以隐藏这个 Show Tags暂时的选择。

关于ios - 点击 `Add Tags` 选项会关闭 UIDocumentInteractionController 突然启动的底层模态视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60347636/

相关文章:

ios - Swift SpriteKit - SKAction 中的 zRotation 跟随路径

objective-c - UIWebView可以播放本地视频吗?

ios - 在 iOS 中调整 JPEG 图像的大小并设置质量,同时保留 EXIF

swift - 在 Swift 中动态调用方法

ios - 为类成员分配和使用协议(protocol)类型变量

ios - 以一定角度将文本绘制到图像上 [Swift 3]

iphone - 将时间添加到日期数组时出现问题

ios - BAD_EXC_ACCESS 用于在释放时尝试加载 View Controller

ios - UITextField 输入文本时的奇怪行为

ios - 根据选定的 TableView 行更新 UILabel