Reputation: 1236
I am having an application which consists of many different file formats like ppt,pdf,txt,png etc, I want to open it whenever the user taps the particular file. How this can be done?Please help me
Can I use WebView for all the files ?
Upvotes: 0
Views: 305
Reputation: 11439
UIWebview allow you to display office documents :
You can open them by loading the file data, example with RTF file :
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"txt"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
[self.webView loadData:myData MIMEType:@"application/rtf" textEncodingName:@"latin1" baseURL:nil];
Or you can load them by creating a request with local path :
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"pdf"];
NSURL *url = [NSURL URLWithStringdfPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
Note that for Office documents with complex layout you will have a very (very) poor rendering. The only solution is to call a separate application that handles this kind of documents (Pages, Quick office, etc)
Have a look at UIDocumentInteractionController to open your documents in another app
Hope this helps, Vincent
Upvotes: 1
Reputation: 7733
Have a look at the quick look framework with UIDocumentInteractionController class it will have you to open different format of file in its view controller.. QuickLook is a framework that provides quick previewing of a range of document types – supported documents include iWork documents, Microsoft Office, Rich Text Format, PDF, images, text files and comma-separated (csv) files. Sample Application
Upvotes: 3