方法一:使用QLPreviewController
#pragma mark 浏览存在沙盒的文件
-(void)quickLook
{
QLPreviewController *QLPreviewVc = [[QLPreviewController alloc] initWithNibName:nil bundle:nil];
QLPreviewVc.dataSource = self;
QLPreviewVc.delegate = self;
[self presentViewController:QLPreviewVc animated:YES completion:nil];
}
#pragma mark QLPreviewControllerDelegate
- (void)previewControllerDidDismiss:(QLPreviewController *)controller
{
thePath = nil;
}
#pragma mark QLPreviewControllerDataSource
// 几个文件 显示
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *) controller
{
return 1;
}
//每个文档的URL
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
if(thePath)
{
return [NSURL URLWithString:thePath];
}
else
{
WTLog(@"NONONONO");
return nil;
}
}
方法二:
使用uiwebView,直接播放
-(void)showWebview
{
NSURL *url = [NSURL URLWithString:self.model.pdfUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0f];
[_wtWebView loadRequest:request];
_wtWebView.delegate = self;
_wtWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
_wtWebView.scalesPageToFit=YES;
_wtWebView.multipleTouchEnabled=YES;
_wtWebView.userInteractionEnabled=YES;
}