#import "WKZViewController.h"
#import <WebKit/WebKit.h>
@interface WKZViewController ()<WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler,WKScriptMessageHandler>
@property(strong,nonatomic) WKWebView *webView;
@end
@implementation WKZViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"登录";
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
//注册js方法
[config.userContentController addScriptMessageHandler:self name:@"jstonative"];
WKWebView *webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 20,[UIScreen mainScreen].bounds.size.width ,[UIScreen mainScreen].bounds.size.height ) configuration:config];
//加载本地页面
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://wxtest.hsmdb.com/htzq/ht_login.html?cnl=zjzxqz"]]];
webView.navigationDelegate = self;
webView.UIDelegate = self;
[self.view addSubview:webView];
}
//实现js调用ios的handle委托
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
//接受传过来的消息从而决定app调用的方法
NSString *dict = message.body;
// {"funcNo":"100001","funName":"loginOut","chnl":"zjzxqz"}
NSData *jsonData = [dict dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
if ([dic[@"funName"] isEqualToString:@"loginOut"]) {
[self.navigationController popViewControllerAnimated:YES];
}
}
OC JS 相互调用(二)(WKZViewController)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一.WKWebView的使用:参考:http://www.360doc.com/content/15/1111/1...
- 前言 Verilog是一种硬件描述语言(HDL),该语言在Windows上有集成开发环境可以使用,如ModelSi...