我不希望我的應用程序添加到「開放的......」列表中,但要獲得列表本身。並將文件發送到其他應用程序。如何在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