HTML 链接无法在 iPod Touch 上打开

发布于 2024-08-24 10:07:10 字数 1120 浏览 8 评论 0原文

我有一个包含链接的 UIWebView。这些链接应该在我的应用程序内的另一个视图中打开,包含“mailto”的链接除外。为了实现这一点,我在 UIWebViews 委托中使用以下代码:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) 
    {
        NSRange mailPos = [[[request URL] absoluteString] rangeOfString:@"mailto:"];
        if (mailPos.location == NSNotFound)
        {
            self.parent.browserView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self.parent.setupViewC presentModalViewController:self.parent.browserView animated:TRUE];
            [self.parent.browserView.wvMainView loadRequest:request];
        }   
        else [[UIApplication sharedApplication] openURL:request.URL];
        return FALSE;
    }
    return TRUE;
}

这在模拟器和 iPhone 上运行良好 - 但在 iPod 上根本不起作用。在 iPod Touch 上单击链接不会执行任何操作。

进行调用

[self.parent.browserView.wvMainView loadRequest:request];

但是,单击 UIButton 后 确实有效。 那么有没有办法让 UIWebView 内部的链接也能在 iPod 上工作呢?

I have an UIWebView containing links. These links should open in another view inside my app, except links containing "mailto". To achieve this, I'm using the following code inside the UIWebViews delegate:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) 
    {
        NSRange mailPos = [[[request URL] absoluteString] rangeOfString:@"mailto:"];
        if (mailPos.location == NSNotFound)
        {
            self.parent.browserView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self.parent.setupViewC presentModalViewController:self.parent.browserView animated:TRUE];
            [self.parent.browserView.wvMainView loadRequest:request];
        }   
        else [[UIApplication sharedApplication] openURL:request.URL];
        return FALSE;
    }
    return TRUE;
}

This works fine in the simulator and on the iPhone - but it doesn't work at all on iPods. Clicking on a link just doesn't do anything on an iPod Touch.

Calling

[self.parent.browserView.wvMainView loadRequest:request];

after a click on an UIButton does work however.
So is there any way to make the links inside the UIWebView work on an iPod too?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酸甜透明夹心 2024-08-31 10:07:10

尝试运行 [[UIApplication sharedApplication] openURL:request.URL];
在主线程中

,在其他情况下尝试以下

[self PerformSelectorOnMainThread:.....];

Try running the [[UIApplication sharedApplication] openURL:request.URL];
in main thread

in the else case try the following

[self performSelectorOnMainThread:.....];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文