Skip to content

Commit 4b5847f

Browse files
author
Jakey
committed
fix error readme
1 parent d386fa0 commit 4b5847f

File tree

7 files changed

+8
-48
lines changed

7 files changed

+8
-48
lines changed

.DS_Store

0 Bytes
Binary file not shown.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
###2.UIWebViews使用代理拦截和JavaScriptCore.framework进行交互
88

9-
* UIWebView 与 JavaScript.framework交互
10-
* JavaScript.framework 与 UIWebView 交互
9+
* UIWebView 与 JavaScript交互
10+
* JavaScript 与 UIWebView 交互
1111

1212
* UIWebView 与 JavaScriptCore.framework交互
1313
* JavaScriptCore.framework 与 UIWebView 交互

iOS-WebView-JavaScript/JavaScriptCore/JSCallOC/JSCallOC.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
function showResult(resultNumber)
3838
{
39-
//alert(resultNumber);
4039
document.getElementById("result").innerText = resultNumber;
4140
}
4241

iOS-WebView-JavaScript/JavaScriptCore/JSCallOC/JSCallOCViewController.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,8 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
4040
{
4141
// 以 html title 设置 导航栏 title
4242
self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
43-
44-
// 禁用 页面元素选择
45-
//[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
46-
47-
// 禁用 长按弹出ActionSheet
48-
//[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
49-
5043
// Undocumented access to UIWebView's JSContext
5144
self.context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
52-
5345
// 打印异常
5446
self.context.exceptionHandler =
5547
^(JSContext *context, JSValue *exceptionValue)

iOS-WebView-JavaScript/WKWebView/JSWKWebViewViewController.m

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ - (void)viewDidLoad {
2525
// 声明WKScriptMessageHandler 协议
2626
[config.userContentController addScriptMessageHandler:self name:@"Native"];
2727

28-
self.myWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) configuration:config];
28+
self.myWebView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
2929
self.myWebView.UIDelegate = self;
30-
[self.view insertSubview:self.myWebView atIndex:0];
30+
[self.view addSubview:self.myWebView];
3131
[self loadTouched:nil];
3232
}
3333

@@ -45,43 +45,12 @@ - (void)userContentController:(WKUserContentController *)userContentController
4545

4646
NSString *func = [param objectForKey:@"func"];
4747

48-
//调用本地函数1
49-
if([func isEqualToString:@"addSubView"])
50-
{
51-
Class tempClass = NSClassFromString([param objectForKey:@"view"]);
52-
CGRect frame = CGRectFromString([param objectForKey:@"frame"]);
53-
54-
if(tempClass && [tempClass isSubclassOfClass:[UIWebView class]])
55-
{
56-
UIWebView *tempObj = [[tempClass alloc] initWithFrame:frame];
57-
tempObj.tag = [[param objectForKey:@"tag"] integerValue];
58-
59-
NSURL *url = [NSURL URLWithString:[param objectForKey:@"urlstring"]];
60-
NSURLRequest *request = [NSURLRequest requestWithURL:url];
61-
[tempObj loadRequest:request];
62-
[self.myWebView addSubview:tempObj];
63-
}
64-
}
65-
//调用本地函数2
66-
else if([func isEqualToString:@"alert"])
48+
//调用本地函数
49+
if([func isEqualToString:@"alert"])
6750
{
6851
[self showMessage:@"来自网页的提示" message:[param objectForKey:@"message"]];
69-
70-
}
71-
//调用本地函数3
72-
else if([func isEqualToString:@"callFunc"])
73-
{
74-
[self testFunc:[param objectForKey:@"first"] withParam2:[param objectForKey:@"second"] andParam3:[param objectForKey:@"third"] ];
75-
7652
}
77-
//调用本地函数4
78-
else if([func isEqualToString:@"testFunc"])
79-
{
80-
[self testFunc:[param objectForKey:@"param1"] withParam2:[param objectForKey:@"param2"] andParam3:[param objectForKey:@"param3"] ];
81-
82-
}
83-
84-
53+
8554
}
8655
}
8756
-(void)testFunc:(NSString*)param1 withParam2:(NSString*)param2 andParam3:(NSString*)param3{

iOS-WebView-JavaScript/WKWebView/WKWebViewJSViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (void)viewDidLoad
2525
[self.view addSubview:self.myWebView];
2626

2727
self.view.backgroundColor = [UIColor grayColor];
28-
self.someString = @"UIWebView是iOS最常用的SDK之一,它有一个stringByEvaluatingJavaScriptFromString方法可以将javascript嵌入页面中,通过这个方法我们可以在iOS中与UIWebView中的网页元素交互";
28+
self.someString = @"iOS 8引入了一个新的框架——WebKit,之后变得好起来了。在WebKit框架中,有WKWebView可以替换UIKit的UIWebView和AppKit的WebView,而且提供了在两个平台可以一致使用的接口。WebKit框架使得开发者可以在原生App中使用Nitro来提高网页的性能和表现,Nitro就是Safari的JavaScript引擎 WKWebView 不支持JavaScriptCore的方式但提供message handler的方式为JavaScript与Native通信";
2929
// self.myWebView.UIDelegate = self;
3030

3131
[self loadTouched:nil];

0 commit comments

Comments
 (0)