views:

306

answers:

3

Hi guys! I want check if my WebView is loading a specific html page locally (for example index2.html). Is that possible? Thanks!!

+1  A: 

You can check its "loading" property to see whether it's done or not. You can check the "request" property to get the NSURLReqest to see what it's loading or has loaded.

NSResponder
+1  A: 

Look at UIWebView delegate methods

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

// examine request to see what url is about to load.
// return YES to allow the load, NO to disallow.
// don't forget to set the delegate:
// myWebView.delegate = self;

    return YES;
}

one of webViewDidFinishLoad or webView:didFailLoadWithError will be called when the request is completed. and as mentioned, checking the "loading" property of your UIWebView object will indicate if something is still be loaded.

if( myWebView.loading ) ...

EDIT: in response to your additional information, (assuming I understand what you're trying to do...) try the following:

// compare scheme property of URL against "file"
if( [[webview1.request.URL scheme] isEqualToString:@"file"] ){
    NSLog(@"load request is local file");
    // ... your code here ...
}

I don't know whether a UIWebView "request" property is valid once the load is finished, haven't tested that. If not, keep a private copy of the most recently loaded URL or request somewhere else.

wkw
A: 

I have used this code:

NSString *currentURL
    = webview1.request.URL.absoluteString;

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"indexPRO" ofType:@"html"];

    urlLocation1 = [NSURL fileURLWithPath:filePath];

    if(currentURL = urlLocation1){ //Do something..

but not work.... Is because I use "absolute string" in currentURL and relative string in "urlLocation1"??

Obliviux
questions belong in the question area, not as an answer
coneybeare