UIWebViewの外部リンクをSafariで開く

投稿者:

.h

.m
uiwebview.delegate = self;
// リンクをクリック時、Safariを起動する為の処理
– (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeOther)
{
NSString* scheme = [[request URL] scheme];
if([scheme compare:@”about”] == NSOrderedSame) {
return YES;
}
if([scheme compare:@”http”] == NSOrderedSame) {
[[UIApplication sharedApplication] openURL: [request URL]];
return NO;
}
}
return YES;
}

Thank you for reading this post, don't forget to subscribe!