在IM项目中,要对接收到的文件进行预览,用QLPreviewController可以预览图片视频等文件。
- (void)openFileWithFilePath:(NSString *)filePath
{
NSURL *URL = [NSURL fileURLWithPath:filePath];
if (URL) {
[_preItemArr removeAllObjects];
[_preItemArr addObject:filePath];
QLPreviewController *myQlPreViewController = [[QLPreviewController alloc]init];
myQlPreViewController.delegate =self;
myQlPreViewController.dataSource =self;
[myQlPreViewController setCurrentPreviewItemIndex:0];
[self presentViewController:myQlPreViewController animated:YES completion:nil];
}
}
#pragma mark -
#pragma mark - QLPreviewController
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:[self.preItemArr objectAtIndex:index]];
}