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では発生しません。これは本当に奇妙なことです。