iOS 第三方应用调用safari

转载自:http://www.2cto.com/kf/201211/171644.html

就用这就能打开safari;
NSURL* url = [[ NSURL alloc ] initWithString :@"http://www.baidu.com"];
[[UIApplication sharedApplication ] openURL: [url autorelease ]];



注: 我在项目中是这样用的:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  


如果当webView内部打开链接时用safari
当然这必须委托给自己
webView.delegate=self;
也当然要加 www.2cto.com
<UIWebViewDelegate>
这样就会自动调用该方法了
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
    NSURL *requestURL =[ [ request URL ] retain ];
    if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ] isEqualToString: @"mailto" ])
        && ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) {
        return ![ [ UIApplication sharedApplication ] openURL: [ requestURL autorelease ] ];
    }
    [ requestURL release ];
    return YES;
}


展开阅读全文

没有更多推荐了,返回首页