iOS显示HTML
2016-06-15 00:00
519 查看
摘要: iOS显示html
进入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);
// };
//}
进入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);
// };
//}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 用js实现下载远程文件并保存在本地的脚本
- 本地 二级域名配置方法
- html文件中jquery与velocity变量中的$冲突的解决方法
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程
- 浅析iOS应用开发中线程间的通信与线程安全问题