0

I am developing an app, which uses UIWebView. I am implementing the manual load counting method as in UIWebView - How to identify the "last" webViewDidFinishLoad message?

I can see the calls for start/finish/failLoad balanced in principle. However, with a few web pages (most particularly, google.com), the page initially loads well and after a few seconds automatically (seems to) refresh itself. The start/finish sequence looks as below:

-[MyWebView webViewDidStartLoad:], 1, 0x895150c
-[MyWebView webView:didFailLoadWithError:], 0, 0x895150c
-[MyWebView webViewDidStartLoad:], 1, 0x895150c
-[MyWebView webViewDidStartLoad:], 2, 0x895150c
-[MyWebView webViewDidFinishLoad:], 1, 0x895150c
-[MyWebView webViewDidFinishLoad:], 0, 0x895150c
-[MyWebView webViewDidStartLoad:], 1, 0x895150c   <-- after a few seconds' gap
-[MyWebView webViewDidFinishLoad:], 0, 0x895150c

The first argument is the function being called, second is the value of the counter and the last value is the address of the loadCounter, just to confirm that it is the same webView instance (and hence the counter) being called. I am running out of clues :(...

Does anyone have any clue, what might be happening here? (BTW, this does not happen for many other websites, so far only with Google)

EDIT: Why it matters to me is, because while it refreshes (apparently randomly), it dismisses the keyboard. This is annoying if a user is already in the middle of typing something. Is it possible to relegate any further refreshes to the site in the background, while continuing the user interaction (particularly keyboard) in the front?

TIA, Nikhil

Community
  • 1
  • 1
Nikhil J Joshi
  • 1,177
  • 2
  • 12
  • 25
  • I suggest you update the question with the information about the virtual keyboard problem. I'm going to delete my answer as it doesn't really get at what you want (and I don't know the fix to the keyboard issue). – DrC Apr 07 '13 at 06:16

1 Answers1

1

As a workaround to avoid the issue - You can listen to keyboard show/hide notifications. Then when you know the keyboard is used, do not allow the web view to perform requests

Update:

First, you'll need to set your view controller to be the webview delegate so that it could respond to the web view delegate messages:

@interface myViewController : UIViewController <UIWebViewDelegate>

Then once the webview object is created, set the view controller to be its delegate:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    someWebView.delegate = self;
}

Now, when the webview will perform its requests it will first consult with the myViewController as it is the associated delegate. This is when you should return NO if you don't want to allow the webview to perform the request.

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

    if (keyboardIsShown == YES){
        return NO;
    }
    else{
        return YES;
    }
}

How do you know if the keyboard is visible at the moment? see this post

Community
  • 1
  • 1
Tom Susel
  • 3,397
  • 1
  • 24
  • 25
  • Hi Tom, Thanks a lot for the suggestion. I am working on it, but could you send me a small example-snippet of how is it done? I am sorry, I have just started working with iOS (or objC for that matter). Thanks again - Nikhil – Nikhil J Joshi Apr 07 '13 at 11:34