1.要把h5写好的项目 放在ios的壳子里面
- (void)viewDidLoad {
[super viewDidLoad];
WKWebView *webview = [[WKWebView alloc]initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height - 20)];
webview.navigationDelegate = self;
NSURL *url = [NSURL URLWithString:@"http://10.10.40.210:8083/eb-web-api/h5/index.html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
[self.view addSubview:webview];
}
2.项目里调用聚合支付时
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
webView.navigationDelegate = self;
webView.opaque = NO;
[webView loadHTMLString:_strurl baseURL:nil];
[self.view addSubview:webView];
}
//拦截到跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
NSURL *url = navigationAction.request.URL;
NSString *urlString = (url) ? url.absoluteString : @"";
if([urlString rangeOfString:@"weixin://"].location !=NSNotFound){
[[UIApplication sharedApplication] openURL:url];
decisionHandler(WKNavigationActionPolicyCancel);
return;
}
decisionHandler(WKNavigationActionPolicyAllow);
}
利用拦截
也可以拦截http ,直接跳转到http网页
网友评论