开发者

How can i download doc or pdf file from UIWebView

I can show url to UIWebView.But How can i开发者_Python百科 download and save a file from UIWebView to folder When the download link is clicked.


Implement webView:shouldStartLoadWithRequest:navigationType: in your web view delegate. If you receive a request to a file that you are interested in, return NO from that method and start a separate NSURLConnection to download the file into an NSData object that you can then save.


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType:(UIWebViewNavigationType)navigationtype
{

    // Will execute this block only when links are clicked
    if( navigationtype == UIWebViewNavigationTypeLinkClicked )
    {
          ...//create NSURLConnection object and save the downloaded bytes in NSData in 
          connectionDidFinishLoading:(NSURLConnection *)connection
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜