views:

731

answers:

2

Hi friends

I want to view .doc, .docx, .rtf, .ppt file in iphone.

But I guess something is going wrong at my side and its not working for the above formats but my code is working fine for .txt and .pdf files.

I have the read the document regarding Webview it states it supports viewing of the above document.

below is my snippet for .doc

[webView loadData:requestData MIMEType:@"application/msword" textEncodingName:@"UTF-8" baseURL:nil];

for .ppt I am using MIME type as "application/vnd.ms-powerpoint"

Note: If I am making MIME type as "text/html" for .doc/.rtf then it displays some garbage data So I think there is something missing in MIME type from my side.

Any help is highly appreciated.

Waiting for your reply.

Update:........

It seems there is some issue with NSData for opening these type of file formats. My data is encrypted so I cannot use requestWithURL directly and other thing is I need to pass credentials to get the file and the credentials doesnt work proplerly if I save the credentials using

[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpace];

and then make the request using below

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]] ]

Is there any way I can use NSData for the above formats so that I can make async call and pass my credentials and then decrypt the data and show it in WebView.

A: 

Try it on an iPhone instead of Simulator

Hwee-Boon Yar
+1  A: 

Not all of those formats (docx) are supported. This looks like the official word. In the example Apple does not specify a mime type.

This question suggests that you must use an NSURLRequest instead of loadData.

Edit:

As far as I have seen, you cannot directly pass data to loadData for these types.

The easy work around is to write to a temporary file. You can delete it in webViewDidFinishLoad or, technically, as soon as the the file has been opened.

The hard work around is to use NSURLCache. You should be able to implement a custom NSURLCache and have WebKit use it via setSharedURLCache. Your cache would basically know how to get your local encrypted files and pretend that they are cached. I have not tried this, but I think it is your best bet. This approach may be blocked just like loadData is.

drawnonward
Thanks for your reply.By data is encrypted so it seems I cannot use NSURLRequest directly. IS there any way I can use NSData to open my .doc, .ppt files.
Ekra
Thanks for your reply.I have the tried the first method its working.Working on second method
Ekra