需求:
調(diào)起網(wǎng)頁,監(jiān)聽返回的點擊事件,返回上一層

Snip20170612_5.png
1. 寫個類,并需要導入#import <JavaScriptCore/JavaScriptCore.h>,所需代碼不上100行
- (void)viewDidLoad{
[super viewDidLoad];
UIWebView *web =[[UIWebView alloc]initWithFrame:CGRectMake(0,-0, LYScreen_Width, LYScreen_Height-64)];
web.delegate = self;
[self.view addSubview:web];
NSURLRequest *httpRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:LYlytUrl]];
[web loadRequest:httpRequest];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
JSContext *jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
LYWeakSelf;
/// 關聯(lián)打印異常
jsContext.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue) {
context.exception = exceptionValue;
};
jsContext[@"closeTopicView"] = ^{ dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.navigationController popViewControllerAnimated:YES];
});
};
}