根據(jù)url的scheme通過相應(yīng)的標(biāo)識獲取url的絕對路徑
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"request.scheme:%@,navigationtype:%d",[request URL].scheme,navigationType);
if ([[request URL].scheme isEqualToString:@"outerurl"] && navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString* urlAbosute = [[[request URL] absoluteString] stringByReplacingOccurrencesOfString:@"outerurl:" withString:@""];
NSString *urlstr=[NSString stringWithFormat:@"https://%@",urlAbosute];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlstr]];
}
if ([[request URL].scheme isEqualToString:@"qq"] && navigationType == UIWebViewNavigationTypeLinkClicked) {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
/*取qq號碼*/
NSLog(@"qqrequest:%@",[[request URL]absoluteString]);
NSRange range=[[[request URL]absoluteString] rangeOfString:@"uin="];
NSString *qqNumber=[[[request URL]absoluteString] substringFromIndex:range.location+range.length];
/*打開QQ鏈接*/
NSString *qqstr=[NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqNumber];
NSURL *url = [NSURL URLWithString:qqstr];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
webView.delegate = self;
[webView loadRequest:request];
[self.view addSubview:webView];
}
return YES;
}