1

我希望有人可以帮助我解决 UIDocumentInteractionController 遇到的一个非常令人沮丧的问题。

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

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

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

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

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

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");
4

1 回答 1

2

只是以为我会为其他有同样问题的人发布更新...我现在认为“打开方式”菜单未出现的原因是由于没有安装带有文件扩展名的应用程序这一简单事实我用过。

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

于 2013-01-29T11:07:39.850 回答