views:

222

answers:

4

I have a Subview that load a Webview. In this Webview I load a file HTML locally in the Documents folder of my App. I need to check if the webview load another HTML file. Specifically: 1) Webview load "index.html" locally in my Documents folder 2) After 7 days a Javascript load another page with "location.href= "index2.html" ", 3) When I load this WebView I need to check if the current URL is index.html or index2.html, if is the second I must change Subview!

How can I do this?

Thanks to everyone can help me!

+3  A: 
NSString *currentUrl = [[[yourWebView request] URL] absoluteString];
jnic
A: 
NSURL *url = myWebView.request.URL;
Prakash
A: 
NSString *currentUrl = [[[yourWebView request] URL] absoluteString];

What is the format of the URL (absoluteString type) for local file??

Obliviux
Should be something like file:///path/to/local/file
nduplessis
But if I use absoluteString like that, for local file, when I go to distribute my application in AppStore, that string may change :(There is another way??
Obliviux
A: 

Use this NSURL method [NSURL fileURLWithPath:@"some/path/to/your/file" isDirectory:NO] and pass that to a NSURLRequest which is then passed to your UIWebView. You can get the path to your resource by using the [[NSBundle mainBundle] pathForResource...] methods.

Sean