我不希望我的应用程序添加到“开放的......”列表中,但要获得列表本身。并将文件发送到其他应用程序。如何在iOS应用程序中使用“打开...”功能?
我工作的内部通讯的应用程序,所以当用户收到一个文件附件时,他/她可以打开任何应用程序安装在每个设备上的文件...
我不希望我的应用程序添加到“开放的......”列表中,但要获得列表本身。并将文件发送到其他应用程序。如何在iOS应用程序中使用“打开...”功能?
我工作的内部通讯的应用程序,所以当用户收到一个文件附件时,他/她可以打开任何应用程序安装在每个设备上的文件...
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;
}
看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
另一种选择:
使用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