2012-03-01 63 views
7

我不希望我的應用程序添加到「開放的......」列表中,但要獲得列表本身。並將文件發送到其他應用程序。如何在iOS應用程序中使用「打開...」功能?

我工作的內部通訊的應用程序,所以當用戶收到一個文件附件時,他/她可以打開任何應用程序安裝在每個設備上的文件...

回答

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; 
} 
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

相關問題