diff --git a/Build/Products/Debug-iphonesimulator/libdsbridge.a b/Build/Products/Debug-iphonesimulator/libdsbridge.a
index 381a811..8dff2b8 100644
Binary files a/Build/Products/Debug-iphonesimulator/libdsbridge.a and b/Build/Products/Debug-iphonesimulator/libdsbridge.a differ
diff --git a/README-chs.md b/README-chs.md
deleted file mode 100644
index 7a2a9ec..0000000
--- a/README-chs.md
+++ /dev/null
@@ -1,188 +0,0 @@
-# DSBridge
-
-> DSBridge是目前地球上最好的IOS/Android javascript bridge. 通过它可以在web和native之间调用彼此方法。DSBridge是目前唯一一个支持同步调用的跨平台Js bridge.
-
-DSBridge-IOS github:https://github.com/wendux/DSBridge-IOS
-
-## 使用
-
-1. Native 实现API 代理类
-
- ```objective-c
- //JsApiTest.m
- @implementation JsApiTest
- //for synchronous invocation
- - (NSString *) testSyn:(NSDictionary *) args
- {
- return [(NSString *)[args valueForKey:@"msg"] stringByAppendingString:@"[ syn call]"];
- }
- //for asynchronous invocation
- - (NSString *) testAsyn:(NSDictionary *) args :(void (^)(NSString * _Nullable result))handler
- {
- handler([(NSString *)[args valueForKey:@"msg"] stringByAppendingString:@"[ asyn call]"]);
- }
- @end
- ```
-
-2. 注册api代理类至DWebview
-
- ```objective-c
- DWebview * webview=[[DWebview alloc] initWithFrame:bounds];
- jsApi=[[JsApiTest alloc] init];
- webview.JavascriptInterfaceObject=jsApi;
- ```
-
-3. 在Javascript中调用Native API
-
- ```javascript
- //Call Native API
- var bridge = getJsBridge();
- //Call synchronously
- var str=bridge.call("testSyn", {msg: "testSyn"});
- //Call asynchronously
- bridge.call("testAsyn", {msg: "testAsyn"}, function (v) {
- alert(v);
- })
-
- //Test will be called by oc, must be global function!
- function test(arg1,arg2){
- return arg1+arg2;
- }
- ```
-
-4. 最后,Native中调用Javascript API
-
- ```objective-c
- [_webview callHandler:@"test"
- arguments:[[NSArray alloc] initWithObjects:@1,@"hello", nil]
- completionHandler:^(NSString * value){
- NSLog(@"%@",value);
- }];
- ```
-
-
-
-## Javascript API 介绍
-
-### getJsBridge
-
-获取javascript bridge 对象;此方法为sdk内置,可在任何地方调用。
-
-### bridge.call(method,[args,callback])
-
-功能:调用Native api
-
-method: api函数名
-
-args:参数,类型:json, 可选参数
-
-callback(String returnValue): 处理调用结果的回调,**仅异步调用时需要**.
-
-
-
-## 注意
-
-### Native API 方法签名
-
-**为了在ios和android平台下兼容,对IOS端Native API接口约定如下:**
-
-1. 所有API返回值类型为NSString, 不存在时返回nil即可。
-2. 参数以JSON传递; DSBridge会将js参数自动转化为NSDictionary
-
-注:JsApiTest.m中实现的方法可以不在JsApiTest.h中声明
-
-### 调用Javascript
-
-DWebView提供了两个api用于调用js
-
-```objective-c
-//调用js api(函数)
--(void)callHandler:(NSString *)methodName arguments:(NSArray * _Nullable)args
- completionHandler:(void (^)(NSString * _Nullable))completionHandler;
-//执行任意js代码
-- (void)evaluateJavaScript:(NSString *)javaScriptString
- completionHandler:(void (^ _Nullable)(NSString * _Nullable))completionHandler;
-```
-
-callHandler中,methodName 为js函数名,args为参数数组,可以接受数字、字符串等。
-
-两个函数中completionHandler为完成回调,用于获取js执行的结果。
-
-**调用时机**
-
-DWebview只有在javascript context初始化成功后才能正确执行js代码,而javascript context初始化完成的时机一般都比整个页面加载完毕要早,随然DSBridge能捕获到javascript context初始化完成的时机,但是一些js api可能声明在页面尾部,甚至单独的js文件中,如果在javascript context刚初始化完成就调用js api, 此时js api 可能还没有加载,所以会失败,为此专门提供了一个api设置一个回调,它会在页面加载结束后调用,为了和didpagefinished区分,我们取名如下:
-
-```objective-c
-- (void)setJavascriptContextInitedListener:(void(^_Nullable)(void))callback;
-```
-
- 若是端上主动调用js,请在此回调中进行 。示例如下:
-
-```objective-c
-__block DWebview * _webview=webview;
-[webview setJavascriptContextInitedListener:^(){
- [_webview callHandler:@"test"
- arguments:[[NSArray alloc] initWithObjects:@1,@"hello", nil]
- completionHandler:^(NSString * value){
- NSLog(@"%@",value);
- }];
-}];
-```
-
-完整的示例请查看demo工程。
-
-
-### 关于DWebview
-
-SDK中有三个webview:
-
-DWKwebview:继承自WKWebView,内部已经实现js prompt、alert、confirm函数对应的对话框。
-
-DUIwebview:继承自UIWebView
-
-DWebview:自定义view, 内部在ios8.0以下会使用DUIwebview, 大于等于8.0会使用DWKwebview。
-
-所有的webview除了都实现了上述api之外,提供了一个加载网页的便捷函数:
-
-```objective-c
-- (void)loadUrl: (NSString *) url;
-```
-
- **您可以根据具体业务使用任意一个**,不过一般情况下优先选用DWebview,它在新设备上更省资源,效率更高。
-
-DWebview还提供了一些其它api和属性,具体请查看其头文件,需要特殊说明的是,有一个api:
-
-```objective-c
-- (id _Nullable) getXWebview;
-```
-
-它可以返回DWebview内部使用的真实webview, 值会是DUIwebview和DWKwebview的实例之一,您可以通过isKindOfClass来判断,吃函数主要用于扩展DWebview,下面可以看一下loadRequest的大概实现:
-
-```objective-c
-- (void)loadRequest:(NSURLRequest *)request
-{
- id webview=[self getXWebview];
- if([webview isKindOfClass:[DUIwebview class]]){
- [(DUIwebview *)webview loadRequest:request];
- }else{
- [(DWKwebview *)webview loadRequest:request];
- }
-}
-```
-
-### Alert dialog
-
-DWebview已经实现 alert、prompt、comfirm对话框,您可以不做处理,也可以自定义。值得一提的是js 在调用alert函数正常情况下只要用户没有关闭alert对话框,js代码是会阻塞的,但是考虑到alert 对话框只有一个确定按钮,也就是说无论用户关闭还是确定都不会影响js代码流程,所以**DWebview中在弹出alert对话框时会先给js返回**,这样一来js就可以继续执行,而提示框等用户关闭时在关闭即可。如果你就是想要阻塞的alert,可以自定义。而DWebview的prompt、comfirm实现完全符合ecma标准,都是阻塞的。
-
-请不要手动设置DUIwebview的delegate属性,因为DUIwebview在内部已经设置了该属性,如果您需要自己处理页面加载过程,请设置WebEventDelegate属性。
-
-### 相关资料
-
-DSBridge-Android:https://github.com/wendux/DSBridge-Android
-
-与WebViewJavascriptBridge的对比 [DSBridge VS WebViewJavascriptBridge]( http://www.jianshu.com/p/d967b0d85b97)。
-
-### 拉票
-
-如果你觉得不错,麻烦star一下以便让更多人知道😄。
-
diff --git a/README.md b/README.md
index 94a477c..7ff1078 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,21 @@
# DSBridge-v2.0
+[![](https://img.shields.io/cocoapods/v/dsBridge.svg?style=flat)](https://jitpack.io/#wendux/DSBridge-Android) [![MIT Licence](https://img.shields.io/packagist/l/doctrine/orm.svg)](https://opensource.org/licenses/mit-license.php)
+
> DSBridge is currently the best Javascript bridge in the world , by which we can call functions synchronously and asynchronously between web and Native . Moreover, both android and ios are supported !
DSBridge-IOS:https://github.com/wendux/DSBridge-IOS
DSBridge-Android:https://github.com/wendux/DSBridge-Android
+2.0更新列表:https://juejin.im/post/593fa055128fe1006aff700a
+
+## Download
+
+```objective-c
+pod "dsBridge"
+```
+
## Usage
1. Implement API delegate class in Object-C
@@ -16,6 +26,7 @@ DSBridge-Android:https://github.com/wendux/DSBridge-Android
//for synchronous invocation
- (NSString *) testSyn:(NSDictionary *) args
{
+ // The return value type can only be NSString
return [(NSString *)[args valueForKey:@"msg"] stringByAppendingString:@"[ syn call]"];
}
//for asynchronous invocation
@@ -36,20 +47,32 @@ DSBridge-Android:https://github.com/wendux/DSBridge-Android
3. Call Object-C API in Javascript, and declare a global javascript function for the following Object-c invocation.
- ```javascript
+ - Init dsBridge
- //Call synchronously
- var str=dsBridge.call("testSyn", {msg: "testSyn"});
- //Call asynchronously
- dsBridge.call("testAsyn", {msg: "testAsyn"}, function (v) {
- alert(v);
- })
+ ```javascript
+ //cdn
+ //
+ //npm
+ //npm install dsbridge
+ var dsBridge=require("dsbridge")
+ ```
- //Register javascrit function for Object-c invocation
- dsBridge.register('addValue',function(r,l){
- return r+l;
- })
- ```
+ - Call API
+
+ ```javascript
+
+ //Call synchronously
+ var str=dsBridge.call("testSyn", {msg: "testSyn"});
+
+ //Call asynchronously
+ dsBridge.call("testAsyn", {msg: "testAsyn"}, function (v) {
+ alert(v);
+ })
+ //Register javascrit function for Native invocation
+ dsBridge.register('addValue',function(l,r){
+ return l+r;
+ })
+ ```
4. Call Javascript function in Object-C .
@@ -93,7 +116,7 @@ function: javascript method body.
In order to be compatible with IOS and Android, we make the following convention on native api signature:
-1. The tye of return value must be NSString; if not need, just return nil.
+1. The tye of return value must be **NSString**; if not need, just return nil.
2. The arguments passed by NSDictionary, if the API doesn't need argument, you still need declare the argument.
### Call javascript code
@@ -138,14 +161,14 @@ __block DWebview * _webview=webview;
There are three webviews available, DWKwebview、DUIwebview and DWebview, all of them provide the same interface, you can user any one you want. It is worth mentioning that the DWebview is just a proxy of DWKwebview and DUIwebview, while the ios system vesion >=8.0 , DWKwebview will be used, otherwise, DUIwebview will be.
-### warnnig
+### Warnnig
If you're using DUIwebview, don't set the delegate prop. because the delegate prop has been setted inner , please set WebEventDelegate instead !
-### Alert dialog
+### Alert/confirm/prompt
-In order to prevent unnecessary obstruction, the alert dialog was implemented asynchronously , that is to say, if you call alert in javascript , it will be returned directly no matter whether the user has to deal with. becase the code flow is not subject to the user operation no matter whether user click ok button or close the alert dialog. if you don't need this feature, you can custom the alert dialog by override "onJsAlert" callback in WebChromeClient class.
+For alert/confirm/prompt dialog, DSBridge has implemented them all by default.
### Finally
-If you like DSBridge, please star to let more people know it , Thank you 😄.
\ No newline at end of file
+If you like DSBridge, please star to let more people know it , Thank you 😄.
diff --git a/dsBridge.podspec b/dsBridge.podspec
new file mode 100644
index 0000000..3e2c8d4
--- /dev/null
+++ b/dsBridge.podspec
@@ -0,0 +1,138 @@
+#
+# Be sure to run `pod spec lint dsBridge.podspec' to ensure this is a
+# valid spec and to remove all comments including this before submitting the spec.
+#
+# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
+# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
+#
+
+Pod::Spec.new do |s|
+
+ # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # These will help people to find your library, and whilst it
+ # can feel like a chore to fill in it's definitely to your advantage. The
+ # summary should be tweet-length, and the description more in depth.
+ #
+
+ s.name = "dsBridge"
+ s.version = "2.0.2"
+ 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.
+ # * Think: What does it do? Why did you write it? What is the focus?
+ # * Try to keep it short, snappy and to the point.
+ # * Write the description between the DESC delimiters below.
+ # * Finally, don't worry about the indent, CocoaPods strips it!
+ s.description = <<-DESC
+ An javascript bridge for calling functions synchronously and asynchronously
+ DESC
+
+ s.homepage = "https://github.com/wendux/DSBridge-IOS.git"
+ # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
+
+
+ # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # Licensing your code is important. See http://choosealicense.com for more info.
+ # CocoaPods will detect a license file if there is a named LICENSE*
+ # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
+ #
+
+ s.license = "MIT"
+ # s.license = { :type => "MIT", :file => "FILE_LICENSE" }
+
+
+ # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # Specify the authors of the library, with email addresses. Email addresses
+ # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
+ # accepts just a name if you'd rather not provide an email address.
+ #
+ # Specify a social_media_url where others can refer to, for example a twitter
+ # profile URL.
+ #
+
+ s.author = { "lazydu" => "824783146@qq.com" }
+ # Or just: s.author = "lazydu"
+ # s.authors = { "lazydu" => "824783146@qq.com" }
+ # s.social_media_url = "http://twitter.com/wen.du"
+
+ # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # If this Pod runs only on iOS or OS X, then specify the platform and
+ # the deployment target. You can optionally include the target after the platform.
+ #
+
+ s.platform = :ios
+ # s.platform = :ios, "5.0"
+
+ # When using multiple platforms
+ # s.ios.deployment_target = "5.0"
+ # s.osx.deployment_target = "10.7"
+ # s.watchos.deployment_target = "2.0"
+ # s.tvos.deployment_target = "9.0"
+
+
+ # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # Specify the location from where the source should be retrieved.
+ # Supports git, hg, bzr, svn and HTTP.
+ #
+
+ s.source = { :git => "https://github.com/wendux/DSBridge-IOS.git", :tag => "#{s.version}" }
+
+
+ # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # CocoaPods is smart about how it includes source code. For source files
+ # giving a folder will include any swift, h, m, mm, c & cpp files.
+ # For header files it will include any header in the folder.
+ # Not including the public_header_files will make all headers public.
+ #
+
+ s.source_files = "dsbridge/*"
+ #s.exclude_files = "Classes/Exclude"
+
+ s.public_header_files = "dsbridge/*.h"
+
+
+ # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # A list of resources included with the Pod. These are copied into the
+ # target bundle with a build phase script. Anything else will be cleaned.
+ # You can preserve files from being cleaned, please don't preserve
+ # non-essential files like tests, examples and documentation.
+ #
+
+ # s.resource = "icon.png"
+ # s.resources = "Resources/*.png"
+
+ # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
+
+
+ # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # Link your library with frameworks, or libraries. Libraries do not include
+ # the lib prefix of their name.
+ #
+
+ # s.framework = "UIKit","JavaScriptCore"
+ # s.frameworks = "SomeFramework", "AnotherFramework"
+
+ # s.library = "iconv"
+ # s.libraries = "iconv", "xml2"
+
+
+ # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
+ #
+ # If your library depends on compiler flags you can set them in the xcconfig hash
+ # where they will only apply to your library. If you depend on other Podspecs
+ # you can include multiple dependencies to ensure it works.
+
+ # s.requires_arc = true
+
+ # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
+ # s.dependency "JSONKit", "~> 1.4"
+
+end
diff --git a/dsbridge.xcodeproj/project.pbxproj b/dsbridge.xcodeproj/project.pbxproj
index 62df9d0..4d27cb4 100644
--- a/dsbridge.xcodeproj/project.pbxproj
+++ b/dsbridge.xcodeproj/project.pbxproj
@@ -27,6 +27,8 @@
818F0BC91E18DD3600679925 /* JsApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 818F0BC81E18DD3600679925 /* JsApiTest.m */; };
818F0BCD1E18E6D200679925 /* libdsbridge.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 818F0B8E1E18C08100679925 /* libdsbridge.a */; };
818F0BD01E1A820B00679925 /* test.html in Resources */ = {isa = PBXBuildFile; fileRef = 818F0BCF1E1A820B00679925 /* test.html */; };
+ 81EBBFFC1EF24A7300D1E4C1 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81EBBFFB1EF24A7300D1E4C1 /* JavaScriptCore.framework */; };
+ 81EBBFFF1EF24DDE00D1E4C1 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 81EBBFFD1EF24DDE00D1E4C1 /* README.md */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -83,6 +85,9 @@
818F0BCB1E18DE7100679925 /* JsApiTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JsApiTest.h; sourceTree = ""; };
818F0BCE1E1A3EEE00679925 /* JSBWebEventDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBWebEventDelegate.h; sourceTree = ""; };
818F0BCF1E1A820B00679925 /* test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = test.html; sourceTree = ""; };
+ 81EBBFF71EF246BD00D1E4C1 /* dsBridge.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsBridge.podspec; sourceTree = ""; };
+ 81EBBFFB1EF24A7300D1E4C1 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
+ 81EBBFFD1EF24DDE00D1E4C1 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -90,6 +95,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 81EBBFFC1EF24A7300D1E4C1 /* JavaScriptCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -107,9 +113,12 @@
818F0B851E18C08100679925 = {
isa = PBXGroup;
children = (
+ 81EBBFFD1EF24DDE00D1E4C1 /* README.md */,
+ 81EBBFF71EF246BD00D1E4C1 /* dsBridge.podspec */,
818F0B901E18C08100679925 /* dsbridge */,
818F0B9F1E18C0AA00679925 /* dsbridgedemo */,
818F0B8F1E18C08100679925 /* Products */,
+ 81EBBFFA1EF24A7300D1E4C1 /* Frameworks */,
);
sourceTree = "";
};
@@ -167,6 +176,14 @@
name = "Supporting Files";
sourceTree = "";
};
+ 81EBBFFA1EF24A7300D1E4C1 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 81EBBFFB1EF24A7300D1E4C1 /* JavaScriptCore.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -263,6 +280,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 81EBBFFF1EF24DDE00D1E4C1 /* README.md in Sources */,
818F0BC01E18C59200679925 /* JSBUtil.m in Sources */,
818F0BBD1E18C58000679925 /* DWebview.m in Sources */,
818F0BB71E18C3B800679925 /* DWKwebview.m in Sources */,
diff --git a/dsbridge/DWKwebview.h b/dsbridge/DWKwebview.h
index 6cde14b..d88bf8e 100644
--- a/dsbridge/DWKwebview.h
+++ b/dsbridge/DWKwebview.h
@@ -10,8 +10,6 @@
@interface DWKwebview : WKWebView
{
- bool confirmDone;
- BOOL confirmResult;
void(^javascriptContextInitedListener)(void);
}
diff --git a/dsbridge/DWKwebview.m b/dsbridge/DWKwebview.m
index 96608c2..c529d25 100644
--- a/dsbridge/DWKwebview.m
+++ b/dsbridge/DWKwebview.m
@@ -10,6 +10,13 @@
#import "JSBUtil.h"
@implementation DWKwebview
+{
+ void(^alertHandler)(void);
+ void (^confirmHandler)(BOOL);
+ void (^promptHandler)(NSString *);
+ int dialogType;
+ UITextField *txtName;
+}
/*
// Only override drawRect: if you perform custom drawing.
@@ -21,6 +28,11 @@ - (void)drawRect:(CGRect)rect {
-(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
{
+ txtName=nil;
+ dialogType=0;
+ alertHandler=nil;
+ confirmHandler=nil;
+ promptHandler=nil;
//NSString * js=@"function setupWebViewJavascriptBridge(b){var a={call:function(d,c){return prompt('_dspiercall='+d,c)}};b(a)};";
NSString * js=[@"_dswk='_dsbridge=';" stringByAppendingString: INIT_SCRIPT];
@@ -63,16 +75,13 @@ - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSSt
initiatedByFrame:frame
completionHandler:completionHandler];
}else{
+ dialogType=3;
+ promptHandler=completionHandler;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:prompt message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
- UITextField *txtName = [alert textFieldAtIndex:0];
+ txtName = [alert textFieldAtIndex:0];
txtName.text=defaultText;
[alert show];
- while (!confirmDone){
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
- }
- confirmDone=false;
- completionHandler([txtName text]);
}
}
}
@@ -89,13 +98,14 @@ - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSStrin
initiatedByFrame:frame
completionHandler:completionHandler];
}else{
+ dialogType=1;
+ alertHandler=completionHandler;
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:@"提示"
message:message
- delegate:nil
+ delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil,nil];
- completionHandler();
[alertView show];
}
}
@@ -110,6 +120,8 @@ -(void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStri
initiatedByFrame:frame
completionHandler:completionHandler];
}else{
+ dialogType=2;
+ confirmHandler=completionHandler;
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:@"提示"
message:message
@@ -117,18 +129,26 @@ -(void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStri
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[alertView show];
- while (!confirmDone){
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
- }
- confirmDone=false;
- completionHandler(confirmResult);
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
- confirmDone=true;
- confirmResult=buttonIndex==1?YES:NO;
+ if(dialogType==1 && alertHandler){
+ alertHandler();
+ alertHandler=nil;
+ }else if(dialogType==2 && confirmHandler){
+ confirmHandler(buttonIndex==1?YES:NO);
+ confirmHandler=nil;
+ }else if(dialogType==3 && promptHandler && txtName) {
+ if(buttonIndex==1){
+ promptHandler([txtName text]);
+ }else{
+ promptHandler(@"");
+ }
+ promptHandler=nil;
+ txtName=nil;
+ }
}
- (void)setJavascriptContextInitedListener:(void (^)(void))callback