简体   繁体   中英

iOS - Download files to application folder

I do have a UIWebview inside one of my UIViewControllers. The destination URL to be displayed within the WebView is a page on my server (therefore I have access to make changes on it).

That page basically has a list of PDFs to be downloaded (imagine an un-ordered list of hyperlinks each pointing to a PDF file).

I need a way to tell my App that whenever a file is downloaded from that WebView by clicking on one of the links, I need it to be saved inside my application folder instead of the iPhone/iPad memory.

Is there any way I can achieve that? Are there alternatives?

You can allow UIWebView to call your Objective-C delegate function. This link provides an overview of how to do it: http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/ Basically, the delegate function will be called on all requests from the UIWebView. You can examine if they are for links to a pdf files, and if so, write your own objective-c code to download the file and store it in your Application directory. You'll probably want to add some UI to let the user know what is happening. Otherwise you let the request go on as normal and it will be displayed in the web browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM