How can I download files from UIWebView using ASIHTTPRequest? - objective-c

I want to create a section of my app where you can download the current webpage showing in the UIWebView and then save it to a UITableView and when you tap on the filename in the UITableView, it will load the local file in the UIWebView to allow offline browsing.
How can I do this with http://allseeing-i.com/ASIHTTPRequest? I've taken a look and all the code looks very daunting for a beginner! Is there an alternative method? Is this the best method?
Thank you

ASIWebPageRequest is the answer. It's a class included with ASIHTTPRequest that makes it easy to download whole pages, with all their associated dependencies.
You'd probably want to create a custom cache to store your downloaded webpages in, and then load them out of that cache when requested by the user.

Related

iOS app files that the user can download from the app

The idea is that i will create a file in the app and store some data in it.
I want for the end user to be able to download that file from the iOS device to his mac/pc.
Is this somehow possible? Where should i put the file for the user to be able to download it via itunes?
Here is good tutorial you can use:
Tutorial
It is important to know, that in iOS, when your user needs to create file, you do not need to care where to save it.
Another possibility for you might be to avoid saving data as file. For example, if your data is picture:
UIImage send to email

Any way to stop UIWebView from opening pdf automatically

Is there a way to stop UIWebView from opening PDF files automatically?
Html file that gets loaded is not local and it holds links (href) to some pdf files. Now I would like those files to be downloaded to some local folder on the device instead of being opened by UIWebView by default when the user touches the link buttons.
Is there any way to do this at all? Oh, and if possible without html/xml parsing since I still want to use UIWebView for browsing other pages?
The reason why I don't want UIWebView to open pdf files is because I want my own custom view to do that instead.
Implement the webView:shouldStartLoadWithRequest:navigationType: delegate method for your web view. Check the navigationType for UIWebViewNavigationTypeLinkClicked to see if it is a link tapped by the user. Check the URL of the request to see if it is for a PDF file.
If it matches these criteria, then return NO from the delegate and do your own processing to download and display the PDF file.

How to access Local file system using Silverlight 4 (Webbrowser control)

Our Silverlight application needs to show to the user previews of HTML pages it generates dynamically, so we want to use the WebBrowser to show these pages. The problem is that the HTML contains links to other local files such as images, flash objects, CSS and javascript files. The CSS and javascript could be placed inline in the HTML, but I haven't found a way to embed images. Something simple like this just doesn't work:
Creating the HTML file and the image file in the isolated storage is doable, but I can't get the path to the created HTML file to pass on to WebBrowser.Navigate(uri).
Reading the contents of the HTML file and calling WebBrowser.NavigateToString(string) will show the page, but not any linked images or scripts.
Linking to online sources is not an option as the application needs to work offline (i.e. out of browser) and performance would be much better if the images and flash objects were able to be cached locally.
So, is there any way in Silverlight of showing in the WebBrowser control a local HTML file that contains an image from the local file system, or is it impossible?
Thanks, sandeep agrawal
The only way to make that work is to make the Silverlight an OOB application, and then you can still only access the My* folders.
I heard that someone wrote a browser control that can be used without going OOB but not sure about that. This is a real pain, but a necessary one I guess.

Loading images from to differenet base resources to the webview

I am implementing a WebView in which I need to use some images. For this, I use the images under the ressources folder and call
[myWebView loadHTMLString:returnString baseURL:[[NSBundle mainBundle] resourceURL]];
It is working fine. In the same time I need to use some external images coming from the server in the same WebView. For this I need to change the baseURL of the target server but I don't know how to handle these two.
How to handle both images, from local and external server in one HTML?
If you use full URLs (i.e. http://www.exmaple.com/myimage.png) for the images coming from the server, they won't be affected by the baseURL parameter, which is only used for resolving relative (partial) URLs.
I think you can create two instance of UIView class and add the UIWebView in both the views.
In the first webview show the image from the resource and in the other webview show the image from the server.
Just give it a try see if this works.

iphone app UIWebView cache data

I need a UIWebView to show a html page. if internet is not available it will show the last downloaded version. if has internet then it downloads the most current version and replaces and shows the version just downloaded. how can I do this? Thanks
You could implement you webViews delegate webViewDidFinishLoad: method to grab the request and load it again. Since it was just finished loading, we can assume that it is cached and load it with synchronous networking. Store the result. When network is unavailable load that result into the webView using loadData:MIMEType:textEncodingName:baseURL:. When network comes available agin just call loadRequest: to refresh.
Another option is to use stringByEvaluatingJavaScriptFromString: with a javascript around:
document.getElementsByTagName('html')[0].outerHTML;
and inserting the content with loadHTMLString:baseURL:
But these two only work for pure HTML without images, sounds, etc.
A third option would be to use the NSURLRequestReturnCacheDataDontLoad when network is not available. see NSURLRequest
You migth also have a look at the NSURLCache