2016-06-01 100 views
0

我需要从API下载文件一样.PPT,.doc或.ppt文件显示在iOS应用

http://52.76.226.179/aapc-social-web/sites/default/files/media_docs/2009/content-601938936.ppt

,并在我的iOS应用程序显示一个预览。

请帮忙。

I have used the quick look framework and UIDocumentInteractionController show me something like this. please see the image and suggest something.

+0

这可能会帮助您:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/QLPreviewController_Class/index.html#//apple_ref/occ/cl/QLPreviewController –

+0

请分享您的代码 – SM18

+0

的NSString * filePath = [[NSBundle mainBundle] pathForResource:@“content-601938936”ofType:@“ppt”]; UIDocumentInteractionController * documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]]; //配置文档交互控制器 [documentInteractionController setDelegate:self]; [documentInteractionController presentPreviewAnimated:YES]; –

回答

0

[UIDocumentInteractionController][1]是你在找什么。
主要区别方面QLPreviewController是它可以显示预览,也可以显示一个UiActionSheet或弹出窗口,显示与该格式兼容的应用程序并将文档的显示委托给它们。
使用它非常容易。检查here

+0

我已经使用过它。 NSString * filePath = [[NSBundle mainBundle] pathForResource:@“content-601938936”ofType:@“ppt”]; UIDocumentInteractionController * documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]]; //配置文档交互控制器 [documentInteractionController setDelegate:self]; [documentInteractionController presentPreviewAnimated:YES]; 但显示我的文件,如http://i.stack.imgur.com/fxQe3.jpg 请建议。 –

+0

我认为这发生在文件不兼容预览时,你确定路径是否正确? – Andrea

+1

我认为你是对的文件有问题。我试着用另一个像魅力一样工作的文件。感谢帮助。 –

2

进口此PKG

#import <QuickLook/QuickLook.h> 

使用此代码视图控制器。

QLPreviewController *previewController=[[QLPreviewController alloc]init]; 
previewController.delegate=self; 
previewController.dataSource=self; 

previewController.view.frame = self.conditionsofUseView.bounds; 
[self.conditionsofUseView addSubview:previewController.view]; 
[self addChildViewController:previewController]; 
[previewController didMoveToParentViewController:self]; 
[previewController.navigationItem setRightBarButtonItem:nil]; 

添加这些代表methodes

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller 
{ 
    return 1; 
} 

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index 
{ 


NSString *filePath = [[NSBundle mainBundle] pathForResource:@"docFileName" ofType:@"file type"]; //doc,ppt,pdf etc 

return [NSURL fileURLWithPath:filePath]; 

} 
相关问题