iOS 预览图片和打开第三方文件

  • 打开图片

引入第三方库XLPhotoBrowser

XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:imageUrlArray currentImageIndex:selectedNum];
browser.browserStyle = XLPhotoBrowserStyleIndexLabel; // 微博样式
  • 打开文件
@property (nonatomic,strong) UIDocumentInteractionController *documentInteractionController;
//创建存储路径
+ (void)creatDir:(NSString*)dirPath{
    if (![[NSFileManager defaultManager] fileExistsAtPath:dirPath]){//判断dirPath路径文件夹是否已存在,此处dirPath为需要新建的文件夹的绝对路径
    
        [[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil];//创建文件夹
    }
}


//创建fileUrl
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *caches = [paths firstObject];
    [CH_Utils creatDir:[caches stringByAppendingString:@"/Documents"]];
    NSString *savedPath = [caches stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",fileName]];

打开URL
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileUrl];
[_documentInteractionController setDelegate:self];
[_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

还有webView和QLPreviewController打开文档,随后更新


你可能感兴趣的:(iOS 预览图片和打开第三方文件)