Reputation: 3965
I am building an iPhone app that can save email attachments. I would like to be able to view the files from inside the application as well. I need to be able to view as many kinds of files as possible: .txt, .pdf, .png, .jpeg., .doc, .xls, etc.
The files will reside inside of my application's documents folder. What is the best solution for this? My first thought is to convert my file-paths to URLs and load them in a UIWebView, but I'm not sure if this is the best way, or if it will handle all those file types. Any thoughts?
Upvotes: 2
Views: 578
Reputation: 535138
The way Apple's own Mail app does this is with the QuickLook framework. I'd suggest you do the same. QLPreviewController does all the heavy lifting for you. You can also use UIDocumentInteractionController; this is still using QuickLook behind the scenes to generate the preview.
Upvotes: 2
Reputation: 3485
The UIWebView is the best way to show this kind of file.
Alternatively you can try to read the document in an other app with this code:
UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController interactionControllerWithURL:document.documentURL] retain];
interactionController.delegate = self;
BOOL canOpenDocument = [interactionController presentOpenInMenuFromRect:CGRectMake(365, 200, 300, 400) inView:self.view animated:YES];
if(!canOpenDocument) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Your phone can't read this kind of file, please install an app from appstore for that" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
Upvotes: 2