开发者

How can i download doc or pdf file from UIWebView

开发者 https://www.devze.com 2023-02-02 02:41 出处:网络
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:navigationTy

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

精彩评论

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