进入H5:
方法一:文件在本地
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *filePath =[resourcePath stringByAppendingPathComponent:@"agreement.html"];
//encoding:NSUTF8StringEncoding error:nil 这一段一定要加,不然中文字会乱码
NSString*htmlstring=[[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlstring baseURL:[NSURL fileURLWithPath:[ [NSBundle mainBundle] bundlePath]]];
方法二:文件在后台
NSURL *url=[NSURL URLWithString:BASE_IMAGE_URL];
[self.webv loadHTMLString:responseDic[@"data"][@"INTRODUCE"] baseURL:url];
方法三:加载连接
NSString *webStr =[NSString stringWithFormat:@"http://121.196.11.24/ceshi/esdphp/index.php/exam/introa?userid=%@",[self.localStore getUserId]];//测试服务器
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:webStr]];
self.webView.delegate = self;
[self.webView loadRequest:request];
跳出H5:
方法一:跳出H5页面的系统方法
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSURL* url = request.URL;
//joyskim:\\showStr?str="hello"
if ([url.scheme isEqualToString:@"apprecall"]) {
//执行逻辑
NSLog(@"%@",url.scheme);
[self regist];
return NO;
}
return YES;
}
方法二:跳出H5页面的路径方法
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
AMOcModel *model = [[AMOcModel alloc] init];
self.jsContext[@"Ios"] = model;
model.jsContext = self.jsContext;
model.webView = self.webView;
// self.jsContext.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue) {
// context.exception = exceptionValue;
// NSLog(@"异常信息:%@", exceptionValue);
// };
//}