ios/Objective C - UIDocumentInteractionController - 'Open In' 方法总是返回 NO

标签 ios objective-c uidocumentinteraction

我希望有人能帮助解决我在使用 UIDocumentInteractionController 时遇到的一个非常令人沮丧的问题。

我需要调用“presentOpenInMenuFromRect”方法,以允许用户在另一个应用程序中打开文件。在这个阶段,我只是在做概念验证,所以我只是使用非常基本的文件类型来进行测试。

我已经使用下面的代码设置了我的 UiDocumentInteractionController,并验证了文件路径 URL 是正确的,因为我可以成功调用 presentPreviewAnimated 方法,并且文档确实可以在预览模式下正常打开。

我遇到的问题是“presentOpenInMenuFromRect”总是返回 NO,无论我使用什么文件类型。到目前为止,我使用了以下常见的文件类型,均无济于事:jpg、png、pdf、txt、rtf 和 html。

如果有人遇到这个问题,我将不胜感激。当然,这些文件中至少有一个应该被设备识别为具有关联的应用程序(并且它预览 OK 的事实实际上不能证明这一点吗?)我想知道我在做一些更根本性的错误吗?顺便说一句,我正在 iPhone 上调试,所以这不是模拟器的怪癖。

非常非常欢迎任何建议!提前致谢。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *filePath = [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:@"test.txt"]];

documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:filePath];
documentInteractionController.delegate = self;
[documentInteractionController retain];

// The following line does work, so we know the UIDocumentInteractionController and filepath are fundamentally correct
// [documentInteractionController presentPreviewAnimated:YES];

// Method ALWAYS returns NO, no matter what file type is used
if (![documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES])
    NSLog(@"Failed to show Open In menu");

最佳答案

只是想我会为遇到同样问题的其他人发布更新...我现在相信“打开方式”菜单没有出现的原因很简单,因为没有安装任何应用程序我使用的文件扩展名。

这现在看起来相当明显,但当时我假设一些更常见的文件类型将与系统应用程序等相关联 - 但是在安装 Adob​​e Reader 后,这现在似乎适用于 pdf。

关于ios/Objective C - UIDocumentInteractionController - 'Open In' 方法总是返回 NO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14475313/

相关文章:

c++ - OpenCV 和 iOS,将图像提取/裁剪成匹配的部分

iphone - AVErrorInvalidVideoComposition = -11841

ios - UIDocumentInteractionController 日历访问

iphone - 如何检查是否有任何应用程序与文件扩展名相关联

ios - UIDocumentInteractionController 的 UINavigationBar 外观

iOS - GKPeerPickerController [picker dismiss] 崩溃

iphone - TableView 部分更改时的方法调用

ios - 为什么 AVAudioPlayer 在拔下耳机后继续播放?

IOS 自定义键盘。如何在自定义键盘中设置特殊字符

objective-c - 新设备上的 IOS 配置文件和推送通知