How can I create a "download manager" which would detect when a link you tap (in a UIWebView) has the file ending ".pdf", ".png", ".jpeg", ".tiff", ".gif", ".doc", ".docx", ".ppt", ".pptx", ".xls" and ".xlsx" and then would open a UIActionSheet asking you if you would like to download or open. If you select download, it will then download that file to the device.
Another section of the app would have a list of downloaded files in a UITableView and when you tap on them, they will show in a UIWebView, but of course offline because they would load locally as they would have been downloaded.
See http://itunes.apple.com/gb/app/downloads-lite-downloader/id349275540?mt=8 for a better understanding of what I am trying to do.
What is the best way of doing this?
Use the method
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
in your UiWebView's delegate to determine when it wants to load resource.When the method get's called, you just need to parse the URL from the parameter
(NSURLRequest *)request
, and return NO if it's one of your desired type and continue with your logic (UIActionSheet) or return YES if the user just clicked a simple link to a HTML file.Makes sense?
Edit_: For better understanding a quick code example
Edit2_: I've updated the code sample after our dicussion about your issues in the chat: