当用户点击网页视图上网页显示的网址链接时,我使用下面的代码启动了Safari:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
if (![[UIApplication sharedApplication] openURL:[request URL]])
return NO;
}
else
{
return YES;
}
}
它适用于iOS 4和iOS 5。
然而,在iOS4上,它启动了safari,但是当我关闭浏览器并返回应用程序时,网页视图仍然继续转到我发送到safari的网址。
如何避免这种情况?
答案 0 :(得分:0)
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
if ([[UIApplication sharedApplication] openURL:[request URL]])
return NO;
}
else
{
return YES;
}
}
答案 1 :(得分:0)
删除后尝试! from if(![[UIApplication sharedApplication] openURL:[request URL]]),如下所示 -
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
if ([[UIApplication sharedApplication] openURL:[request URL]])
return NO;
}
else
{
return YES;
}
}
它可能对你有帮助....