2

当用户点击网页视图上显示的网页的 URL 链接时,我使用下面的代码启动 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,但是当我关闭浏览器并返回应用程序时,web 视图继续转到我发送给 safari 的 url。

如何避免这种情况?

4

2 回答 2

0

删除后试试!来自 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;
        }
    }

它可以帮助你......

于 2012-04-10T10:33:57.410 回答
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;
    }
}
于 2012-04-10T07:23:20.083 回答