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
}
}
精彩评论