【发布时间】:2011-04-05 09:08:21
【问题描述】:
我在 uiwebview 中有一个网页。这个页面上有几个 http:// 链接。其中一个我想在 safari 中打开它。其余的可以在 UIWebview 中打开。 到目前为止,我使用了此代码;
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *requestURL = [ [ request URL ] retain ];
// Check to see what protocol/scheme the requested URL is.
if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ]
|| [ [ requestURL scheme ] isEqualToString: @"https" ] )
&& ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];
}
// Auto release
[ requestURL release ];
// If request url is something other than http or https it will open
// in UIWebView. You could also check for the other following
// protocols: tel, mailto and sms
return YES;
}
这适用于 http 和 https 等。我的想法是让网站的链接之一指向 safari://blah.com 并将上面的代码更改为;
if ( ( [ [ requestURL scheme ] isEqualToString: @"safari" ]
|| [ [ requestURL scheme ] isEqualToString: @"https" ] )
希望这会在 safari 中打开 safari:// url,其余部分在 UIWebview 中打开。但没有运气。 似乎只有标准的东西(如 http https tel mailto 和 sms)在这里工作。 任何想法如何解决这个问题?
【问题讨论】:
-
我知道我们将在这里进行两年,但是您会接受我的回答,因为它有很多赞成票并且实际上是解决方案吗?我可以使用我第一个接受的答案! :)