HTML 链接无法在 iPod Touch 上打开
我有一个包含链接的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试运行 [[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:.....];