【发布时间】:2013-02-28 05:22:07
【问题描述】:
我的应用创建了一个名为 log.txt 的简单文件
这个文件的 URL(在 xcode 中查看)是 file://localhost/var/mobile/Applications/NUMBER OF THE APPLICATION/Documents/log.txt
所以我可以在 finder 中看到这个文件...
我想在我的应用程序中添加“打开方式”功能,以便用户共享此文件(通过邮件或 imessage)或在另一个兼容的应用程序中打开此文件。
这是我的工作:
-(void) openDocumentIn {
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:docFile]; //docFile is the path
//NSLog(@"%@",fileURL); // -> shows the URL in the xcode log window
UIDocumentInteractionController *documentController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
documentController.delegate = self;
documentController.UTI = @"public.text";
[documentController presentOpenInMenuFromRect:CGRectZero
inView:self.view
animated:YES];
}
然后调用这个函数:
-(IBAction)share:(id)sender {
[self openDocumentIn];
}
当我运行应用程序时,我点击了这个“分享”按钮,但除了在日志窗口中显示 URL 的路径外,什么都没有附加...
我错过了一些东西......
谢谢
编辑:最后,它可以在我真正的 iphone 上运行……模拟器中没有文本查看器!!! --'
编辑 2:它显示了可用的应用程序(页面、凹凸...)但最终崩溃:(((!see here for the crash picture
【问题讨论】:
-
您确定您的设备上安装了可以打开该文件类型的应用程序吗?
-
在我的帖子中查看编辑和编辑 2
-
打开断点导航器,点击右下角的+号,添加异常断点,完成。再次运行应用程序,现在调试器将在抛出异常时停止。
-
2013-03-12 17:27:00.545 newapp[1930:907] -[__NSCFType _openDocumentWithApplication:]: unrecognized selector sent to instance 0x1dd7e220 这是否意味着我的 txt 文件无法通过页面打开? ??
标签: iphone ios xcode file share