我有一个在 UITableView 中列出文件列表的应用程序。这些文件是 .ifc 文件(3D 渲染)我下载了另一个名为 Field3D 的应用程序,它显示下载的 .ifc 文件。目前我的应用程序确实下载了这个文件,我正在寻找使用 UIActivityViewController 这样用户就可以与 Field3D 应用程序共享这个文件。我被告知应用程序间通信是可行的方法,所以我做了一些研究并找到了这个 https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html
现在它在将文件和数据发送到另一个应用程序下说我所要做的就是以下内容:
- (void)displayActivityControllerWithDataObject:(id)obj {
UIActivityViewController* vc = [[UIActivityViewController alloc]
initWithActivityItems:@[obj] applicationActivities:nil];
[self presentViewController:vc animated:YES completion:nil];
}
但我不相信这会像那样工作,因为我的 UIActivityViewController 代码非常相似
NSData *pdfData = [NSData dataWithContentsOfFile:filePath];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:@[pdfData] applicationActivities:nil];
activityController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityController animated:YES completion:^{}];
有人可以帮我指出正确的方向吗?
最佳答案
您应该能够使用 UIDocumentInteractionController
让用户使用 Field3D 打开文件。
iOS 应用程序作为“IPA”文件分发,它只是一个包含应用程序包和一些其他元数据文件的 ZIP 文件。我在 iTunes 中下载了 Field3D 并解压缩了 IPA,然后查看了该应用程序的 Info.plist(使用 plutil -convert json -r -o - Info.plist
)以查看它注册的文档类型为了。其中,它将自己注册为 com.tekla.collada3d.ifc
的处理程序,文件扩展名为 ifc
和 com.tekla.collada3d.ifczip
文件扩展名为 ifczip
。
因此,如果您将文件存储在本地(大概在您的应用程序沙箱的 Documents
或 Caches
目录中),扩展名为 .ifc
或.ifczip
,您应该能够让 Field3D 处理它,只需提供一个用(本地)文件的 URL 初始化的 UIDocumentInteractionController
。如果需要,您可以将交互 Controller 的 UTI
属性显式设置为 com.tekla.collada3d.ifc
或 com.tekla.collada3d.ifczip
而不是依赖文件扩展名。
有关详细信息,请阅读 “Previewing and Opening Files” in Document Interaction Programming Topics for iOS .
关于ios - Objective-C - 应用程序间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34170607/