ios app hits straight shouldstartloadwithrequest after coming from background instead

心已入冬 提交于 2019-12-12 01:32:38

问题


I have a webview in my mainviewcontroller and i am laoding a webpage in viewdidload method as below:

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [_loginWebView loadRequest:requestObj];


}

and in the shouldstartloadwithrequest method, i check if the url contains "itunes" and i have the following code for it:

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


NSRange textRange4;
            textRange4 =[[[request URL] absoluteString] rangeOfString:@"itunes.apple.com"];
            if(textRange4.location != NSNotFound)
            {

               UIApplication *app = [UIApplication sharedApplication];
                NSString *newPath = [[request URL] absoluteString] ;

                if ([newPath rangeOfString:@"insider"].location != NSNotFound) {
                    NSURL *myURL = [NSURL URLWithString:@"insider://"];
                    if ([app canOpenURL:myURL]) {
                        [app openURL:myURL];
                        NSLog(@"insider");

                    }
                    else 
                    {
                        [app openURL:[NSURL URLWithString:newPath]];
                    }


                }
                else if ([newPath rangeOfString:@"reuters-news-pro-for-ipad"].location != NSNotFound) {

                      [app openURL:[NSURL URLWithString:newPath]];

                }
                else if ([newPath rangeOfString:@"thomson-reuters-marketboard"].location != NSNotFound) {
                    NSURL *myURL = [NSURL URLWithString:@"marketboard://"];
                    if ([app canOpenURL:myURL]) {
                        [app openURL:myURL];
                        NSLog(@"marketboard");
                    }
                    else
                    {
                       [app openURL:[NSURL URLWithString:newPath]];
                    }


                }
                else
                {
                    [app openURL:[NSURL URLWithString:newPath]];

                }

                return NO;

            }
return YES;
}

the above code works it opens the apps i desire but when I go back to my app from ipad, instead of going to the mainviewcontroller, it reopens the previous opened app. for example if I opened marketboard app, it reopens it when i tap the app icon from ipad home. But the above only happens in ios5.0, it does not happen in 6.0 which is really weird


回答1:


It is the default behaviour when you have webview loadrequest in viewdidload method in ios5.0 and they have fixed it in ios6.0



来源:https://stackoverflow.com/questions/14491584/ios-app-hits-straight-shouldstartloadwithrequest-after-coming-from-background-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!