美文网首页
iOS 使用UIDocumentInteractionContr

iOS 使用UIDocumentInteractionContr

作者: 肉身佛陀 | 来源:发表于2017-03-14 20:52 被阅读115次

部分代码

self.documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
//        [self.documentController presentPreviewAnimated:YES];
        self.documentController.delegate    =   (id)self;
        BOOL canOpen = [self.documentController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
        if (!canOpen) {
            [self.view makeToast:@"沒有程序可以打开选中的文件"];
        }

实现代理

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    
    return self;
}

可以打开该文件的应用列表弹框

注意:如图,当选取第三方应用的弹框已出现,点击选取应用后没有跳转,一定是URL有问题;
使用真机测试时,每次运行,存储在沙盒中文件的地址都会改变,主要是NSHomeDirectory()地址的改变引起。

相关文章

网友评论

      本文标题:iOS 使用UIDocumentInteractionContr

      本文链接:https://www.haomeiwen.com/subject/gkzhnttx.html