ios应用程序从后台进入后直接命中应该在startstartloadwithrequest [英] ios app hits straight shouldstartloadwithrequest after coming from background instead

查看:120
本文介绍了ios应用程序从后台进入后直接命中应该在startstartloadwithrequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的mainviewcontroller中有一个webview,并且正在用viewdidload方法加载一个网页,如下所示:

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];


}

,并在shouldstartloadwithrequest方法中,检查URL是否包含"itunes",并且具有以下代码:

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;
}

上面的代码有效,它可以打开我想要的应用程序,但是当我从ipad回到我的应用程序时,而不是转到mainviewcontroller时,它会重新打开以前打开的应用程序. 例如,如果我打开了marketboard应用程序,则当我从ipad主页上点击应用程序图标时,它将重新打开它. 但是上述情况仅在ios5.0中发生,而在6.0中则没有发生,这真的很奇怪

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

推荐答案

在ios5.0的viewdidload方法中具有webview loadrequest时,这是默认行为 他们已经在ios6.0中修复了它

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

这篇关于ios应用程序从后台进入后直接命中应该在startstartloadwithrequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆