# LYSCommonWKWebKit **Repository Path**: canxijie_admin/lyscommon-wkweb-kit ## Basic Information - **Project Name**: LYSCommonWKWebKit - **Description**: 使用WKWebView解决开发中,H5与原生混合过程中,js和原生交互繁琐,逻辑复杂,频繁交换数据的问题 - **Primary Language**: Objective-C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-10-19 - **Last Updated**: 2022-10-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LYSCommonWKWebKit #### 介绍 使用WKWebView解决开发中,H5与原生混合过程中,js和原生交互繁琐,逻辑复杂,频繁交换数据的问题 #### 安装教程 1. pod 'LYSCommonWKWebKit' #### 使用说明 ```ObjC self.webView = [[LYSCommonWKWeb alloc] initWithFrame:self.view.bounds]; [self.view addSubview:self.webView]; self.webView.jsDelegate = self; self.webView.lifeDelegate = self; //self.webView.autoShowHudEnable = NO; //self.webView.statuAutoShowErrorDes = NO; //self.webView.showNetRefreshBtn = NO; //self.webView.scrollEnable = YES; //[self.webView ly_loadUrl:@"http://10.89.133.237:8080"]; [self.webView ly_loadUrl:@"https://www.baidu.com"]; ``` #### 添加异步方法 ```ObjC [self.webView ly_addAsynAction:@selector(getUserInfo:) target:self name:@"getUserInfo"]; - (void)getUserInfo:(id)obj { LYSBridgeInfo *info = (LYSBridgeInfo *)obj; NSLog(@"%@",info.allParms); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.webView ly_evaluateResponse:@{@"name":@"1121"} success:YES message:@"成功!" bridge:info]; }); } ``` #### 回调属性 数据结构 ```ObjC - (void)ly_evaluateResponse:(NSDictionary *)response success:(BOOL)success message:(NSString *)message bridge:(LYSBridgeInfo *)bridge { dispatch_async(dispatch_get_main_queue(), ^{ NSArray *tempAry = [self getBridgesWith:bridge.bridgeName]; for (LYSBridgeInfo *model in tempAry) { NSData *dictData = [NSJSONSerialization dataWithJSONObject:@{ @"bridgeName":model.bridgeName, @"message":message, @"success":@(success), @"data":response, @"callbackId":model.callbackId } options:(NSJSONWritingPrettyPrinted) error:nil]; NSString *dictStr = [[NSString alloc] initWithData:dictData encoding:NSUTF8StringEncoding]; NSString *jsString = [NSString stringWithFormat:@"%@(%@)",self.globalPushString,dictStr]; [self.webView evaluateJavaScript:jsString completionHandler:^(id _Nullable data, NSError * _Nullable error) {}]; [self removeBridge:model]; } }); } ``` #### 默认属性 ```ObjC self.globalCallString = @"callNativeBridgeApi"; self.globalPushString = @"JsBridgeInvoke"; self.globalObjectSting = @"dx"; self.autoShowHudEnable = YES; self.autoShowStatusEnable = NO; self.statuAutoShowErrorDes = YES; self.showNetRefreshBtn = YES; self.showNetDesLabel = YES; self.showNetIcon = YES; self.scrollEnable = NO; ```