4

The following code works fine but when I go back to my app it keeps on executing the following code but I don't know why and how to stop it. I think it is only happening in ios5.0 : app flow - rootviewcontroller -> mainviewcontroller ->webview

the following code is called in shouldstartloadrequest method of a webview in mainviewcontroller

@property (readwrite, retain) UIWebView *_loginWebView;
...
..
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_loginWebView loadRequest:requestObj];
}

//following gets called whenever webview gets a request to open url

   - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
            //return no is a special case there is more code in the method which I am not showing here
           if ([[UIApplication sharedApplication] canOpenURL:myURL]) 
           {
                  [[UIApplication sharedApplication] openURL:myURL];
           }
           else
           {
                  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:newPath]];
           }
           return NO;
     }
     //above is a special case

}

head tag content -

<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
  <!-- iOS Stuff -->
  <link rel="apple-touch-icon" href="images/...."/>
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <link rel="shortcut icon" href="favicon.ico" />
  <script async="async" src="https://......."></script>
  <script type="text/javascript">
..........
  </script>
</head>
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Jatin
  • 1,668
  • 2
  • 16
  • 23
  • Where is this code being called? What method? – jmstone617 Jan 18 '13 at 00:41
  • shouldstartloadrequest method – Jatin Jan 18 '13 at 00:42
  • Well, by reading the two available answers I couldn't understand your problem. You don't want the webview to refresh everytime your app goes to foreground right? What I would say is that you get some control flags that you can check on webview:shouldStartLoadRequest: and decide if you want it to load or not. The fact is that we don't know why it's called and maybe this is its behavior. If that's so you just have to go around it. If this seems completely off then maybe I didn't understand a thing. – Fábio Oliveira Jan 24 '13 at 08:16
  • may be i put it in a wrong way - try this - http://stackoverflow.com/questions/14491584/ios-app-hits-straight-shouldstartloadwithrequest-after-coming-from-background-in – Jatin Jan 24 '13 at 14:06

3 Answers3

0

does myURL have a meta refresh set in the header? If the web page is reloading, this method will get called. It will also get called if there are redirects.

jmstone617
  • 5,707
  • 2
  • 24
  • 26
0

If I understand your question well, the problem is

  1. start your app, go to the mainViewController, after the view did load, it will let iOS to open a url in another application.
  2. the other application is opened, and when you back to your application, the web view reload the url automatically.

so, problem is why the webview reload the url automaticlly.

from the code above, it likes there is no need to use web view, because the delegate always return No, and do something others.

I don't know why this happens now, if you can , just remove the web view troubled this.

and this answer will be deleted.

Wubao Li
  • 1,728
  • 10
  • 13
  • thanks wubao this is what i thought too but the 2nd time around viewidload doesn't even get called, it is hitting shouldstartloadwithrequest straight when i go back to the app – Jatin Jan 18 '13 at 03:35
  • I have already tried C with no luck, I have got a temporary solution using nsnotification - UIApplicationWillEnterForegroundNotification but still loking for a better solution – Jatin Jan 18 '13 at 03:38
  • return no is a special case there is more code in the mehtod which I am not showing here – Jatin Jan 18 '13 at 14:19
  • hey could you repost your A,B,C – Jatin Jan 21 '13 at 17:06
0

It was a bug with IOS 5.0 where if you went back to a webview on app's return to foreground, it refreshes it....just the way safari does it...

but apple fixed this bug in IOS 6.0

So nothing could've been done about it.

Jatin
  • 1,668
  • 2
  • 16
  • 23