UIApplication sharedApplication keeps executing when going back to the app and relaunching

StackOverflow https://stackoverflow.com/questions/14342480

  •  15-01-2022
  •  | 
  •  

Question

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>
Was it helpful?

Solution 3

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top