Skip to content

Commit 2d321e7

Browse files
问题修复
2 parents 7b7f130 + b0b09d0 commit 2d321e7

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
## 介绍
2828

29-
**iOS 基于WKWebView的JS-Native交互框架,功能强大,轻松集成,两行代码即可,业务框架分离,易于拓展。**
29+
**iOS 基于WKWebView的JS-Native交互框架,功能强大,轻松集成,一行代码即可,业务框架分离,易于拓展。**
3030
**关于通信方案说明:**
3131
* WKWebView使用addScritMessageHandler构建通信,苹果提供的bridge,可以理解为亲儿子,好处自然不用多说。
3232

@@ -40,7 +40,7 @@
4040
![image text](https://github.com/GitWangKai/WKJavaScriptBridge/blob/master/img_1.jpg)
4141

4242
## 特性
43-
- 两行代码即可让WebView能力无限
43+
- 一行代码即可让WebView能力无限
4444
- 针对WKWebView进行了Cookie丢失处理。
4545
- 针对WKWebView白框架屏问题进行了处理。
4646
- 针对WKWebView所带来的一些Crash问题进行了容错处理。
@@ -64,7 +64,7 @@
6464

6565

6666
## 用法
67-
`WKWebViewEngine`是框架的主体类,对外提供两个函数:`bindBridgeWithWebView:`传入你的webView,`setWebViewDelegate:`传入你的controller,用来拦截webView的代理函数。具体参照demo。
67+
`WKWebViewEngine`是框架的主体类,对外提供`bindBridgeWithWebView:withDelegate:`接口,用来拦截webView的代理函数。具体参照demo。
6868

6969
### 1.使用框架
7070

@@ -78,8 +78,7 @@ configuration.preferences = preferences;
7878
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
7979
webView.navigationDelegate = self;
8080
/***/
81-
WKWebViewEngine* bridge = [WKWebViewEngine bindBridgeWithWebView:webView];
82-
[bridge setWebViewDelegate:self];
81+
[WKWebViewEngine bindBridgeWithWebView:webView withDelegate:self];
8382
/***/
8483
[self.view addSubview:webView];
8584
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"index.html" ofType:nil];
@@ -147,25 +146,26 @@ configuration.processPool = self.processPool;
147146

148147
```objc
149148
#import "WKBasePlugin.h"
150-
@interface WKTestUIWebViewPlguin : WKBasePlugin
151-
- (void)nativeTestUIWebView:(WKMsgCommand *)command;
149+
@interface WKFetchPlugin : WKBasePlugin
150+
- (void)nativeFentch:(WKMsgCommand *)command;
152151
@end
153152

154153
```
155154
156155
```objc
157-
@WKRegisterWebPlugin(WKTestUIWebViewPlguin, 1)
158-
159-
@implementation WKTestUIWebViewPlguin
160-
- (void)nativeTestUIWebView:(WKMsgCommand *)command {
161-
NSString *method = [command argumentAtIndex:0];
162-
NSString *url = [command argumentAtIndex:1];
163-
NSString *param = [command argumentAtIndex:2];
164-
NSLog(@"(%@):%@,%@,%@",command.callbackId, method, url, param);
165-
166-
WKPluginResult *result = [WKPluginResult resultWithStatus:WKCommandStatus_OK messageAsString:@"uiwebview test success!"];
156+
@WKRegisterWebPlugin(WKFetchPlugin)
157+
158+
@implementation WKFetchPlugin
159+
- (void)nativeFentch:(WKMsgCommand *)command {
160+
NSString *method = [command.arguments objectForKey:@"method"];
161+
NSString *url = [command.arguments objectForKey:@"url"];
162+
163+
NSLog(@"method : %@ ; url : %@", method, url);
164+
165+
WKPluginResult *result = [WKPluginResult resultWithStatus:WKCommandStatus_ERROR messageAsDictionary:@{@"result": @"success!!"}];
167166
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
168167
}
168+
169169
@end
170170
```
171171

0 commit comments

Comments
 (0)