我的 mainviewcontroller 中有一个 webview,我正在 viewdidload 方法中加载一个网页,如下所示:
- (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 回到我的应用程序时,而不是去主视图控制器,它会重新打开以前打开的应用程序。例如,如果我打开了 marketboard 应用程序,当我从 ipad 主页点击应用程序图标时,它会重新打开它。但是上面只发生在ios5.0,它不会发生在6.0,这真的很奇怪