diff --git a/Build/Products/Debug-iphonesimulator/libdsbridge.a b/Build/Products/Debug-iphonesimulator/libdsbridge.a
index 75a3916..a4d4e3a 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 467b434..8d282f8 100644
--- a/README.md
+++ b/README.md
@@ -67,6 +67,8 @@ To use a dsBridge in your own project:
1. Implement APIs in a class
```objective-c
+ #import "dsbridge.h"
+ ...
@implementation JsApiTest
//for synchronous invocation
- (NSString *) testSyn:(NSString *) msg
@@ -74,7 +76,7 @@ To use a dsBridge in your own project:
return [msg stringByAppendingString:@"[ syn call]"];
}
//for asynchronous invocation
- - (void) testAsyn:(NSString *) msg :(void (^)(NSString * _Nullable result,BOOL complete))completionHandler
+ - (void) testAsyn:(NSString *) msg :(JSCallback)completionHandler
{
completionHandler([msg stringByAppendingString:@" [ asyn call]"],YES);
}
@@ -95,9 +97,9 @@ To use a dsBridge in your own project:
```javascript
//cdn
- //
+ //
//npm
- //npm install dsbridge@3.1.1
+ //npm install dsbridge@3.1.4
var dsBridge=require("dsbridge")
```
@@ -142,7 +144,13 @@ In order to be compatible with IOS , we make the following convention on Object
2. For asynchronous API.
- **` (void) handler:(id) arg :(void (^)( id result,BOOL complete))completionHandler)`**
+ **` (void) handler:(id) arg :(JSCallback)completionHandler)`**
+
+ `JSCallback` is a block type:
+
+ ```objective-c
+ typedef void (^JSCallback)(NSString * _Nullable result,BOOL complete);
+ ```
> Attention: API name can't start with "init", because it is reserved in OC class.
@@ -166,6 +174,8 @@ Two points you should keep in mind:
- Must add "@objc" to Swift API.
- Must use "_" to ignore the first argument name explicitly
+The complete example is [here](https://github.com/wendux/DSBridge-IOS/blob/master/dsbridgedemo/JsApiTestSwift.swift) .
+
## Namespace
Namespaces can help you better manage your APIs, which is very useful in hybrid applications, because these applications have a large number of APIs. DSBridge (>= v3.0.0) allows you to classify API with namespace. And the namespace can be multilevel, between different levels with '.' division.
@@ -188,7 +198,7 @@ Normally, when a API is called to end, it returns a result, which corresponds on
In Object-c
```objective-c
-- ( void )callProgress:(NSDictionary *) args :(void (^)(NSNumber * _Nullable result,BOOL complete))completionHandler
+- ( void )callProgress:(NSDictionary *) args :(JSCallback)completionHandler
{
value=10;
hanlder=completionHandler;
@@ -256,7 +266,7 @@ Example:
{
return arg;
}
-- (void) asyn: (id) arg :(void (^)( id _Nullable result,BOOL complete))completionHandler
+- (void) asyn: (id) arg :(JSCallback)completionHandler
{
completionHandler(arg,YES);
}
diff --git a/dsBridge.podspec b/dsBridge.podspec
index cb01294..b309fc4 100644
--- a/dsBridge.podspec
+++ b/dsBridge.podspec
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#
s.name = "dsBridge"
- s.version = "3.0.3"
+ s.version = "3.0.4"
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 bf198cb..09cb715 100644
--- a/dsbridge.xcodeproj/xcuserdata/du.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/dsbridge.xcodeproj/xcuserdata/du.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -339,5 +339,21 @@
landmarkType = "7">
+
+
+
+
diff --git a/dsbridge/DWKWebView.h b/dsbridge/DWKWebView.h
index 929f5a6..365f526 100644
--- a/dsbridge/DWKWebView.h
+++ b/dsbridge/DWKWebView.h
@@ -8,6 +8,8 @@
#import
+typedef void (^JSCallback)(NSString * _Nullable result,BOOL complete);
+
@interface DWKWebView : WKWebView
@property (nullable, nonatomic, weak) id DSUIDelegate;
diff --git a/dsbridge/dsbridge.h b/dsbridge/dsbridge.h
index 2483075..a710eab 100644
--- a/dsbridge/dsbridge.h
+++ b/dsbridge/dsbridge.h
@@ -9,3 +9,4 @@
#import
#import "JSBUtil.h"
#import "DWKWebView.h"
+
diff --git a/dsbridgedemo/JsApiTest.h b/dsbridgedemo/JsApiTest.h
index 39440fc..498829a 100644
--- a/dsbridgedemo/JsApiTest.h
+++ b/dsbridgedemo/JsApiTest.h
@@ -7,6 +7,7 @@
//
#import
+#import "dsbridge.h"
@interface JsApiTest : NSObject
diff --git a/dsbridgedemo/JsApiTest.m b/dsbridgedemo/JsApiTest.m
index a1211cb..d1da4e6 100644
--- a/dsbridgedemo/JsApiTest.m
+++ b/dsbridgedemo/JsApiTest.m
@@ -21,7 +21,7 @@ - (NSString *) testSyn: (NSString *) msg
return [msg stringByAppendingString:@"[ syn call]"];
}
-- (void) testAsyn:(NSString *) msg :(void (^)(NSString * _Nullable result,BOOL complete))completionHandler
+- (void) testAsyn:(NSString *) msg :(JSCallback) completionHandler
{
completionHandler([msg stringByAppendingString:@" [ asyn call]"],YES);
}
@@ -31,12 +31,12 @@ - (NSString *)testNoArgSyn:(NSDictionary *) args
return @"testNoArgSyn called [ syn call]";
}
-- ( void )testNoArgAsyn:(NSDictionary *) args :(void (^)(NSString * _Nullable result,BOOL complete))completionHandler
+- ( void )testNoArgAsyn:(NSDictionary *) args :(JSCallback)completionHandler
{
completionHandler(@"testNoArgAsyn called [ asyn call]",YES);
}
-- ( void )callProgress:(NSDictionary *) args :(void (^)(NSNumber * _Nullable result,BOOL complete))completionHandler
+- ( void )callProgress:(NSDictionary *) args :(JSCallback)completionHandler
{
value=10;
hanlder=completionHandler;
@@ -62,7 +62,7 @@ -(void)onTimer:t{
* redirect requests to native, more about Fly see https://github.com/wendux/fly
* @param requestInfo passed by fly.js, more detail reference https://wendux.github.io/dist/#/doc/flyio-en/native
*/
--(void)onAjaxRequest:(NSDictionary *) requestInfo :(void (^)(NSString * _Nullable result,BOOL complete))completionHandle{
+-(void)onAjaxRequest:(NSDictionary *) requestInfo :(JSCallback)completionHandler{
}
diff --git a/dsbridgedemo/JsApiTestSwift.swift b/dsbridgedemo/JsApiTestSwift.swift
index f3c301e..4d84f73 100644
--- a/dsbridgedemo/JsApiTestSwift.swift
+++ b/dsbridgedemo/JsApiTestSwift.swift
@@ -7,6 +7,7 @@
//
import Foundation
+typealias JSCallback = (String, Bool)->Void
class JsApiTestSwift: NSObject {
@@ -15,7 +16,7 @@ class JsApiTestSwift: NSObject {
return String(format:"%@[Swift sync call:%@]", arg, "test")
}
- @objc func testAsyn( _ arg:String, handler: (String, Bool)->Void) {
+ @objc func testAsyn( _ arg:String, handler: JSCallback) {
handler(String(format:"%@[Swift async call:%@]", arg, "test"), true)
}
diff --git a/dsbridgedemo/JsEchoApi.m b/dsbridgedemo/JsEchoApi.m
index aa61bf0..005e52b 100644
--- a/dsbridgedemo/JsEchoApi.m
+++ b/dsbridgedemo/JsEchoApi.m
@@ -7,6 +7,7 @@
//
#import "JsEchoApi.h"
+#import "dsbridge.h"
@implementation JsEchoApi
@@ -15,7 +16,7 @@ - (id) syn:(id) arg
return arg;
}
-- (void) asyn: (id) arg :(void (^)( id _Nullable result,BOOL complete))completionHandler
+- (void) asyn: (id) arg :(JSCallback)completionHandler
{
completionHandler(arg,YES);
}
diff --git a/readme-chs.md b/readme-chs.md
index 0ad2655..4a0ca84 100644
--- a/readme-chs.md
+++ b/readme-chs.md
@@ -44,6 +44,8 @@ pod "dsBridge"
1. 新建一个类,实现API
```objective-c
+ #import "dsbridge.h"
+ ...
@implementation JsApiTest
//同步API
- (NSString *) testSyn:(NSString *) msg
@@ -51,7 +53,7 @@ pod "dsBridge"
return [msg stringByAppendingString:@"[ syn call]"];
}
//异步API
- - (void) testAsyn:(NSString *) msg :(void (^)(NSString * _Nullable result,BOOL complete))completionHandler
+ - (void) testAsyn:(NSString *) msg :(JSCallback)completionHandler
{
completionHandler([msg stringByAppendingString:@" [ asyn call]"],YES);
}
@@ -73,9 +75,9 @@ pod "dsBridge"
```javascript
//cdn方式引入初始化代码(中国地区慢,建议下载到本地工程)
- //
+ //
//npm方式安装初始化代码
- //npm install dsbridge@3.1.1
+ //npm install dsbridge@3.1.4
var dsBridge=require("dsbridge")
```
@@ -120,6 +122,12 @@ pod "dsBridge"
**` (void) handler:(id)arg :(void (^)( id result,BOOL complete))completionHandler)`**
+ `JSCallback` 是一个block类型:
+
+ ```objective-c
+ typedef void (^JSCallback)(NSString * _Nullable result,BOOL complete);
+ ```
+
> 注意:API名字**不能**以"init"开始,因为oc的类中是被预留的, 如果以"init"开始,执行结果将无法预期(很多时候会crash)。
>
@@ -145,6 +153,8 @@ pod "dsBridge"
- 必须给Swift API添加 "@objc" 标注。
- 必须给第一个参数前添加下划线"_"来显式忽略参数名
+完整的示例在 [这里](https://github.com/wendux/DSBridge-IOS/blob/master/dsbridgedemo/JsApiTestSwift.swift) .
+
## 命名空间
命名空间可以帮助你更好的管理API,这在API数量多的时候非常实用,比如在混合应用中。DSBridge (>= v3.0.0) 支持你通过命名空间将API分类管理,并且命名空间支持多级的,不同级之间只需用'.' 分隔即可。
@@ -169,7 +179,7 @@ pod "dsBridge"
In Object-c
```objective-c
-- ( void )callProgress:(NSDictionary *) args :(void (^)(NSNumber * _Nullable result,BOOL complete))completionHandler
+- ( void )callProgress:(NSDictionary *) args :(JSCallback)completionHandler
{
value=10;
hanlder=completionHandler;
@@ -237,7 +247,7 @@ DSBridge已经实现了 Javascript的弹出框函数(alert/confirm/prompt),这
{
return arg;
}
-- (void) asyn: (id) arg :(void (^)( id _Nullable result,BOOL complete))completionHandler
+- (void) asyn: (id) arg :(JSCallback)completionHandler
{
completionHandler(arg,YES);
}