部分代码
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()
地址的改变引起。
网友评论