0

mainviewcontrollerにWebビューがあり、以下のようにviewdidloadメソッドでWebページをロードしています。

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [_loginWebView loadRequest:requestObj];


}

そして、shouldstartloadwithrequestメソッドで、URLに「itunes」が含まれているかどうかを確認し、次のコードを使用しています。

- (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からアプリに戻ると、メインビューコントローラーに移動する代わりに、前に開いたアプリを再度開きます。たとえば、マーケットボードアプリを開いた場合、iPadホームからアプリアイコンをタップすると再び開きます。しかし、上記はios5.0でのみ発生し、6.0では発生しません。これは本当に奇妙なことです。

4

1 に答える 1

0

これは、ios5.0のviewdidloadメソッドにwebview loadrequestがあり、ios6.0で修正された場合のデフォルトの動作です。

于 2013-03-05T18:15:37.090 に答える