Q: How do I display iWork, Office, or other document types in my iPhone OS Application?
A: In addition to HTML content, UIWebView can display specific document types.
iPhone OS 2.2.1 supports the following document types:
-
Excel (.xls)
-
Keynote (.key.zip)
-
Numbers (.numbers.zip)
-
Pages (.pages.zip)
-
PDF (.pdf)
-
Powerpoint (.ppt)
-
Word (.doc)
IMPORTANT: Excel, Powerpoint and Word documents must be saved using Microsoft Office 97 or newer formats.
Keynote, Numbers and Pages documents must be created with iWork '06 or iWork '08. iWork '06 and iWork '08 documents are document packages and must be ZIP compressed for UIWebView to recognize them. You must retain both extensions in the file name, such as presentation.key.zip, spreadsheet.numbers.zip or paper.pages.zip. iWork '09 documents are not supported on iPhone OS 2.2.1.
iPhone OS 3.0 supports these additional document types:
-
Rich Text Format (.rtf)
-
Rich Text Format Directory (.rtfd.zip)
-
Keynote '09 (.key)
-
Numbers '09 (.numbers)
-
Pages '09 (.pages)
IMPORTANT: Rich Text Format Directory (.rtfd) documents are document packages and must be ZIP compressed for UIWebView to recognize them. You must retain both extensions in the file name, such as document.rtfd.zip.
iWork '09 documents do not use a package format and must not be ZIP compressed.
To display supported documents in a UIWebView, create an NSURL as a file URL with the path to the document. Listing 1 demonstrates a method that uses a UIWebView to load a document from your application bundle.
Listing 1: Loading a document into a UIWebView.
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
// Calling -loadDocument:inView:
[self loadDocument:@"mydocument.rtfd.zip" inView:self.myWebview];
From: http://developer.apple.com/library/ios/#qa/qa2008/qa1630.html
本文介绍如何使用UIWebView在iOS应用中展示多种类型的文档,包括iWork、Office文档及PDF等,并提供代码示例。

被折叠的 条评论
为什么被折叠?



