如何在iOS应用中使用“open in ...”功能?

时间:2012-03-01 09:39:21

标签: iphone ios ipad

我不打算将我的应用添加到“打开...”列表中,而是将列表本身添加到列表中。并将文件发送到另一个应用程序。

我正在开发内部通信应用程序,因此当用户收到文件附件时,他/她可以使用每个设备上安装的任何应用程序打开该文件...

3 个答案:

答案 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)

答案 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