如何在Safari中打开网址而不是在webview中 [英] how to open the url in safari not in webview

查看:110
本文介绍了如何在Safari中打开网址而不是在webview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在safari中打开一个网址,超出应用程序,而不是在webview中。

I want to open an url in safari, outisde the app and not in webview.

我实现了 UIWebViewDelegate 但我仍然无法打开网址。
基本上我无法点击网址。

I implemented the UIWebViewDelegate but I am still not able to open the url. Basically I am not able to click the url.

以下是代码:

-(void)newView:(NSString *)title Description:(NSString *)desc URL:(NSString *)url{
    webView =[[UIWebView alloc]initWithFrame:CGRectMake(15, 17, 190, 190)];
    webView.backgroundColor=[UIColor clearColor];
    webView.delegate=self;
    webView.opaque = NO;
    [webView loadHTMLString:[NSString stringWithFormat:@"<html><body p style='color:white' text=\"#FFFFFF\" face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\">%@ %@</body></html>", desc,url] baseURL:nil];

    v = [[HUDView alloc] initWithFrame:CGRectMake(60, 70, 220, 220)];

    cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.frame = CGRectMake(0, 0, 30, 30);
    [cancelButton setBackgroundImage:[UIImage imageNamed:@"closebox.png"] forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(cancelButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [v addSubview:cancelButton];
    [v addSubview:webView];
    [self.view addSubview:v];  
}

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }

    return YES;
}


推荐答案

阅读评论之后我认为这就是你要找的东西:

After reading the comments I think this is what you're looking for:

实现这个方法:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

来自 UIWebViewDelegate 并取决于该请求参数你应该返回 TRUE FALSE 。如果您不希望Web视图打开它,您应该致电:

from UIWebViewDelegate and depending on that request argument you should return TRUE or FALSE. If you don't want the web view to open it, you should call:

[[UIApplication sharedApplication] openURL:request.URL];

正如其他人提到的那样并返回 FALSE

as others mentioned and return FALSE.

希望这会有所帮助。干杯!

Hope this helps. Cheers!

编辑:如果您的网络视图中无法识别链接,请尝试以下操作:

If the links are not recognized in your web view, try this:

[webView setDataDetectorTypes:UIDataDetectorTypeLink]

这篇关于如何在Safari中打开网址而不是在webview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆