diff --git a/Build/Products/Debug-iphonesimulator/libdsbridge.a b/Build/Products/Debug-iphonesimulator/libdsbridge.a index a4d4e3a..1651447 100644 Binary files a/Build/Products/Debug-iphonesimulator/libdsbridge.a and b/Build/Products/Debug-iphonesimulator/libdsbridge.a differ diff --git a/README.md b/README.md index 8d282f8..644cb4b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +English| [中文简体](https://github.com/wendux/DSBridge-IOS/blob/master/readme-chs.md) # DSBridge for IOS ![dsBridge](https://github.com/wendux/DSBridge-IOS/raw/master/img/dsbridge.png) @@ -8,9 +9,7 @@ > Modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native applications. - - -Chinese documentation [中文文档](https://github.com/wendux/DSBridge-IOS/blob/master/readme-chs.md) + DSBridge-Android:https://github.com/wendux/DSBridge-Android diff --git a/dsBridge.podspec b/dsBridge.podspec index b309fc4..d13e2c9 100644 --- a/dsBridge.podspec +++ b/dsBridge.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "dsBridge" - s.version = "3.0.4" + s.version = "3.0.5" s.summary = "An ios bridge for calling functions synchronously and asynchronously between JavaScript and Object-C in WKWebView/UIWebView" # This description is used to generate tags and improve search results. diff --git a/dsbridge.xcodeproj/xcuserdata/du.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/dsbridge.xcodeproj/xcuserdata/du.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 09cb715..c965ffe 100644 --- a/dsbridge.xcodeproj/xcuserdata/du.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/dsbridge.xcodeproj/xcuserdata/du.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -211,118 +211,6 @@ landmarkType = "7"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dsbridge/DWKWebView.m b/dsbridge/DWKWebView.m index 16de54e..9656317 100644 --- a/dsbridge/DWKWebView.m +++ b/dsbridge/DWKWebView.m @@ -1,21 +1,15 @@ -// -// DSWKwebview.m -// -// Created by wendu on 16/12/28. -// Copyright © 2016 wendu. All rights reserved. -// - #import "DWKWebView.h" #import "JSBUtil.h" #import "DSCallInfo.h" #import "InternalApis.h" +#import @implementation DWKWebView { void (^alertHandler)(void); void (^confirmHandler)(BOOL); void (^promptHandler)(NSString *); - void(^javascriptCloseWindowListener)(void); + void(^javascriptCloseWindowListener)(void); int dialogType; int callId; bool jsDialogBlock; @@ -48,12 +42,12 @@ -(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration isPending=false; isDebug=false; dialogTextDic=@{}; - + WKUserScript *script = [[WKUserScript alloc] initWithSource:@"window._dswk=true;" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]; [configuration.userContentController addUserScript:script]; - self = [super initWithFrame:frame configuration: configuration]; + self = [super initWithFrame:frame configuration: configuration]; if (self) { super.UIDelegate=self; } @@ -83,7 +77,7 @@ - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSSt } } completionHandler(result); - + }else { if(!jsDialogBlock){ completionHandler(nil); @@ -102,11 +96,12 @@ - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSSt if(jsDialogBlock){ promptHandler=completionHandler; } - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:prompt - message:@"" - delegate:self - cancelButtonTitle:dialogTextDic[@"promptCancelBtn"]?dialogTextDic[@"promptCancelBtn"]:@"取消" - otherButtonTitles:dialogTextDic[@"promptOkBtn"]?dialogTextDic[@"promptOkBtn"]:@"确定", + UIAlertView *alert = [[UIAlertView alloc] + initWithTitle:prompt + message:@"" + delegate:self + cancelButtonTitle:dialogTextDic[@"promptCancelBtn"]?dialogTextDic[@"promptCancelBtn"]:@"取消" + otherButtonTitles:dialogTextDic[@"promptOkBtn"]?dialogTextDic[@"promptOkBtn"]:@"确定", nil]; [alert setAlertViewStyle:UIAlertViewStylePlainTextInput]; txtName = [alert textFieldAtIndex:0]; @@ -151,8 +146,8 @@ -(void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStri if(!jsDialogBlock){ completionHandler(YES); } - if( self.DSUIDelegate && [self.DSUIDelegate respondsToSelector: - @selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)]) + if( self.DSUIDelegate&& [self.DSUIDelegate respondsToSelector: + @selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)]) { return[self.DSUIDelegate webView:webView runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame @@ -188,25 +183,30 @@ - (void)webViewDidClose:(WKWebView *)webView{ } - (BOOL)webView:(WKWebView *)webView shouldPreviewElement:(WKPreviewElementInfo *)elementInfo{ - if( self.DSUIDelegate && [self.DSUIDelegate respondsToSelector: - @selector(webView:shouldPreviewElement:)]){ - return [self.DSUIDelegate webView:webView shouldPreviewElement:elementInfo]; - } + if( self.DSUIDelegate + && [self.DSUIDelegate respondsToSelector: + @selector(webView:shouldPreviewElement:)]){ + return [self.DSUIDelegate webView:webView shouldPreviewElement:elementInfo]; + } return NO; } - (UIViewController *)webView:(WKWebView *)webView previewingViewControllerForElement:(WKPreviewElementInfo *)elementInfo defaultActions:(NSArray> *)previewActions{ - if( self.DSUIDelegate && [self.DSUIDelegate respondsToSelector: - @selector(webView:previewingViewControllerForElement:defaultActions:)]){ - return [self.DSUIDelegate webView:webView previewingViewControllerForElement:elementInfo defaultActions:previewActions]; + if( self.DSUIDelegate && + [self.DSUIDelegate respondsToSelector:@selector(webView:previewingViewControllerForElement:defaultActions:)]){ + return [self.DSUIDelegate + webView:webView + previewingViewControllerForElement:elementInfo + defaultActions:previewActions + ]; } return nil; } - (void)webView:(WKWebView *)webView commitPreviewingViewController:(UIViewController *)previewingViewController{ - if( self.DSUIDelegate && [self.DSUIDelegate respondsToSelector: - @selector(webView:commitPreviewingViewController:)]){ + if( self.DSUIDelegate + && [self.DSUIDelegate respondsToSelector:@selector(webView:commitPreviewingViewController:)]){ return [self.DSUIDelegate webView:webView commitPreviewingViewController:previewingViewController]; } } @@ -223,7 +223,7 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto if(buttonIndex==1){ promptHandler([txtName text]); }else{ - promptHandler(@""); + promptHandler(@""); } promptHandler=nil; txtName=nil; @@ -246,7 +246,7 @@ - (void) evalJavascript:(int) delay{ -(NSString *)call:(NSString*) method :(NSString*) argStr { NSArray *nameStr=[JSBUtil parseNamespace:[method stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; - //id JavascriptInterfaceObject= [javaScriptNamespaceInterfaces objectForKey:nameStr[0]]; + id JavascriptInterfaceObject=javaScriptNamespaceInterfaces[nameStr[0]]; NSString *error=[NSString stringWithFormat:@"Error! \n Method %@ is not invoked, since there is not a implementation for it",method]; NSMutableDictionary*result =[NSMutableDictionary dictionaryWithDictionary:@{@"code":@-1,@"data":@""}]; @@ -263,7 +263,6 @@ -(NSString *)call:(NSString*) method :(NSString*) argStr if(arg==[NSNull null]){ arg=nil; } - //if(arg) NSString * cb; do{ if(args && (cb= args[@"_dscbstub"])){ @@ -297,20 +296,15 @@ -(NSString *)call:(NSString*) method :(NSString*) argStr } }; - - SuppressPerformSelectorLeakWarning( - [JavascriptInterfaceObject performSelector:selasyn withObject:arg withObject:completionHandler]; - - ); + void(*action)(id,SEL,id,id) = (void(*)(id,SEL,id,id))objc_msgSend; + action(JavascriptInterfaceObject,selasyn,arg,completionHandler); break; } }else if([JavascriptInterfaceObject respondsToSelector:sel]){ id ret; - SuppressPerformSelectorLeakWarning( - ret=[JavascriptInterfaceObject performSelector:sel withObject:arg]; - ); - + id(*action)(id,SEL,id) = (id(*)(id,SEL,id))objc_msgSend; + ret=action(JavascriptInterfaceObject,sel,arg); [result setValue:@0 forKey:@"code"]; if(ret!=nil){ [result setValue:ret forKey:@"data"]; @@ -385,7 +379,7 @@ - (void) dispatchJavascriptCall:(DSCallInfo*) info{ - (void) addJavascriptObject:(id)object namespace:(NSString *)namespace{ if(namespace==nil){ - namespace=@""; + namespace=@""; } if(object!=NULL){ [javaScriptNamespaceInterfaces setObject:object forKey:namespace]; @@ -409,22 +403,22 @@ - (id)onMessage:(NSDictionary *)msg type:(int)type{ id ret=nil; switch (type) { case DSB_API_HASNATIVEMETHOD: - ret= [self hasNativeMethod:msg]?@1:@0; - break; + ret= [self hasNativeMethod:msg]?@1:@0; + break; case DSB_API_CLOSEPAGE: - [self closePage:msg]; - break; + [self closePage:msg]; + break; case DSB_API_RETURNVALUE: - ret=[self returnValue:msg]; - break; + ret=[self returnValue:msg]; + break; case DSB_API_DSINIT: - ret=[self dsinit:msg]; - break; + ret=[self dsinit:msg]; + break; case DSB_API_DISABLESAFETYALERTBOX: - [self disableJavascriptDialogBlock:[msg[@"disable"] boolValue]]; - break; + [self disableJavascriptDialogBlock:[msg[@"disable"] boolValue]]; + break; default: - break; + break; } return ret; } @@ -483,9 +477,9 @@ - (void) disableJavascriptDialogBlock:(bool) disable{ } - (void)hasJavascriptMethod:(NSString *)handlerName methodExistCallback:(void (^)(bool exist))callback{ - [self callHandler:@"_hasJavascriptMethod" arguments:@[handlerName] completionHandler:^(NSNumber* _Nullable value) { - callback([value boolValue]); - }]; + [self callHandler:@"_hasJavascriptMethod" arguments:@[handlerName] completionHandler:^(NSNumber* _Nullable value) { + callback([value boolValue]); + }]; } @end diff --git a/dsbridge/InternalApis.h b/dsbridge/InternalApis.h index 9f32148..688d55c 100644 --- a/dsbridge/InternalApis.h +++ b/dsbridge/InternalApis.h @@ -1,11 +1,3 @@ -// -// InternalApis.h -// dsbridge -// -// Created by du on 2018/1/30. -// Copyright © 2018年 杜文. All rights reserved. -// - #import #import "DWKWebView.h" diff --git a/dsbridge/InternalApis.m b/dsbridge/InternalApis.m index 3b64a06..528b3c3 100644 --- a/dsbridge/InternalApis.m +++ b/dsbridge/InternalApis.m @@ -1,11 +1,3 @@ -// -// InternalApis.m -// dsbridge -// -// Created by du on 2018/1/30. -// Copyright © 2018年 杜文. All rights reserved. -// - #import "InternalApis.h" #import "JSBUtil.h" diff --git a/dsbridge/JSBUtil.h b/dsbridge/JSBUtil.h index 58a639e..c2a6b6f 100644 --- a/dsbridge/JSBUtil.h +++ b/dsbridge/JSBUtil.h @@ -1,21 +1,5 @@ -// -// Util.h -// dspider -// -// Created by 杜文 on 16/12/27. -// Copyright © 2016年 杜文. All rights reserved. -// - #import -#define SuppressPerformSelectorLeakWarning(Stuff) \ -{ \ -_Pragma("clang diagnostic push") \ -_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \ -Stuff; \ -_Pragma("clang diagnostic pop") \ -} - enum{ DSB_API_HASNATIVEMETHOD, DSB_API_CLOSEPAGE, diff --git a/dsbridge/JSBUtil.m b/dsbridge/JSBUtil.m index ac0632f..21f8f65 100644 --- a/dsbridge/JSBUtil.m +++ b/dsbridge/JSBUtil.m @@ -15,7 +15,6 @@ + (NSString *)objToJsonString:(id)dict NSString *jsonString = nil; NSError *error; - // judgement ---HaoCold 2018-08-23 09:42:09 if (![NSJSONSerialization isValidJSONObject:dict]) { return @"{}"; } diff --git a/dsbridge/dsbridge.h b/dsbridge/dsbridge.h index a710eab..7974c40 100644 --- a/dsbridge/dsbridge.h +++ b/dsbridge/dsbridge.h @@ -1,11 +1,3 @@ -// -// jsbridge.h -// jsbridge -// -// Created by 杜文 on 17/1/1. -// Copyright © 2017年 杜文. All rights reserved. -// - #import #import "JSBUtil.h" #import "DWKWebView.h" diff --git a/dsbridgedemo/test.html b/dsbridgedemo/test.html index d2533f8..732ba64 100644 --- a/dsbridgedemo/test.html +++ b/dsbridgedemo/test.html @@ -48,10 +48,9 @@ hasNativeMethod("testSyn")