我不打算将我的应用添加到“打开...”列表中,而是将列表本身添加到列表中。并将文件发送到另一个应用程序。
我正在开发内部通信应用程序,因此当用户收到文件附件时,他/她可以使用每个设备上安装的任何应用程序打开该文件...
答案 0 :(得分:11)
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:appFile]];
self.controller.delegate = self;
CGRect navRect = self.view.frame;
[self.controller presentOptionsMenuFromRect:navRect inView:self.view animated:YES];
实施以下UIDocumentInteractionControllerDelegate
方法
#pragma mark - UIDocumentInteractionControllerDelegate
//===================================================================
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return self.view.frame;
}
答案 1 :(得分:2)
查看UIDocumentInteractionController https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html和https://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/OpeningSupportedFileTypes.html#//apple_ref/doc/uid/TP40010412-SW1
答案 2 :(得分:0)
另一种选择:
使用UIActivityViewController
版本
iOS 6.0 >
//create instance with file URL
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:@[fileURLHere] applicationActivities:nil];
//present it
[self presentViewController:activity animated:YES completion:NULL];
注意:使用UIDocumentInteractionController
时可能会出现问题。查看uidocumentinteractioncontroller-stopped-working-ios-8