Skip to content

Commit

Permalink
1. update doc
Browse files Browse the repository at this point in the history
2. upgrade to v3.0.1
  • Loading branch information
duwen committed Feb 6, 2018
1 parent eb9708a commit c76ab5a
Show file tree
Hide file tree
Showing 9 changed files with 560 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: objective-c
xcode_project: dsbridge.xcodeproj
xcode_scheme: dsbridge
Binary file modified Build/Products/Debug-iphonesimulator/libdsbridge.a
Binary file not shown.
81 changes: 77 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
# DSBridge

[![](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)
[![](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) [![](https://travis-ci.org/wendux/DSBridge-IOS.svg?branch=master)](https://travis-ci.org/wendux/DSBridge-IOS)
> Modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native applications.
### Notice

DSBridge v3.0 is a milestone. Compared with v2.0.X, we have made a lot of changes. Note that V3.0 is **incompatible** with V2.0, but v2.0 will continue to maintain. If you are a new user, use >=v3.0.
DSBridge v3.0 is a milestone version. Compared with v2.0, we have made a lot of changes. Note that v3.0 is **incompatible** with v2.0, but v2.0 will continue to maintain. If you are a new user, use >=v3.0.

[DSBridge v3.0.0 change list](https://github.com/wendux/DSBridge-IOS/issues/25)



## Features

1. The three ends of Android, IOS and Javascript are easy to use, light and powerful, safe and strong

2. Both synchronous and asynchronous calls are supported

3. Support **API Object**, which centrally implements APIs in a Java Class or a Javascript object

4. Support API namespace

5. Support debug mode

6. Support the test of whether API exists

7. Support **Progress Callback**: one call, multiple returns

8. Support event listener for Javascript to close the page

9. Support Modal and Modeless popup box for javascript

10. Support the X5 webcore of Tencent for Android


## Installation

```shell
pod "dsBridge"
```



## Examples

See the `dsbridgedemo/` package. run the `app` project and to see it in action.

To use a dsBridge in your own project:



## Usage

1. Implement APIs in a class
Expand Down Expand Up @@ -118,9 +148,52 @@ In debug mode, some errors will be prompted by a popup dialog , and the exceptio
[dwebview setDebugMode:true];
```
## Progress Callback
Normally, when a API is called to end, it returns a result, which corresponds one by one. But sometimes a call need to repeatedly return multipule times, Suppose that on the Native side, there is a API to download the file, in the process of downloading, it will send the progress information to Javascript many times, then Javascript will display the progress information on the H5 page. Oh...You will find it is difficult to achieve this function. Fortunately, DSBridge supports **Progress Callback**. You can be very simple and convenient to implement a call that needs to be returned many times. Here's an example of a countdown:

In Object-c

```objective-c
- ( void )callProgress:(NSDictionary *) args :(void (^)(NSNumber * _Nullable result,BOOL complete))completionHandler
{
value=10;
hanlder=completionHandler;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(onTimer:)
userInfo:nil
repeats:YES];
}
-(void)onTimer:t{
if(value!=-1){
hanlder([NSNumber numberWithInt:value--],NO);
}else{
hanlder(@"",YES);
[timer invalidate];
}
}
```

In Javascript

```javascript
dsBridge.call("callProgress", function (value) {
document.getElementById("progress").innerText = value
})
```

For the complete sample code, please refer to the demo project.



## Javascript popup box

For Javascript popup box functions (alert/confirm/prompt), DSBridge has implemented them all by default. the default dialog label text language is Chinese, you can custom the text by calling `customJavascriptDialogLabelTitles`. If you still want to implement them by yourself , set the `DSUIDelegate` property which is a proxy of `WKUIDelegate`.
For Javascript popup box functions (alert/confirm/prompt), DSBridge has implemented them all by default. the default dialog label text language is Chinese, you can custom the text by calling `customJavascriptDialogLabelTitles`. If you still want to implement them by yourself , set the `DSUIDelegate` property which is a proxy of `WKUIDelegate`.

Note That the default dialog box implemented by DSBridge is modal. This will block the UI thread. If you need modeless, please refer to `disableJavascriptDialogBlock`.



Expand Down Expand Up @@ -171,7 +244,7 @@ dsBridge.call("echo.asyn",{msg:" I am echoAsyn call",tag:2},function (ret) {

##### `removeJavascriptObject:(NSString *) namespace`

Remove the Java API object with supplied namespace.
Remove the Object-c API object with supplied namespace.



Expand Down
2 changes: 1 addition & 1 deletion dsBridge.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "dsBridge"
s.version = "3.0.0"
s.version = "3.0.1"
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.
Expand Down
6 changes: 6 additions & 0 deletions dsbridge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 */; };
81CFC8602029456C00CF9D83 /* readme-chs.md in Sources */ = {isa = PBXBuildFile; fileRef = 81CFC85F2029456C00CF9D83 /* readme-chs.md */; };
81EBBFFF1EF24DDE00D1E4C1 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 81EBBFFD1EF24DDE00D1E4C1 /* README.md */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -81,6 +82,8 @@
818F0BCB1E18DE7100679925 /* JsApiTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JsApiTest.h; sourceTree = "<group>"; };
818F0BCE1E1A3EEE00679925 /* JSBWebEventDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBWebEventDelegate.h; sourceTree = "<group>"; };
818F0BCF1E1A820B00679925 /* test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = test.html; sourceTree = "<group>"; };
81CFC85F2029456C00CF9D83 /* readme-chs.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "readme-chs.md"; sourceTree = "<group>"; };
81CFC861202953CB00CF9D83 /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
81EBBFF71EF246BD00D1E4C1 /* dsBridge.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsBridge.podspec; sourceTree = "<group>"; };
81EBBFFD1EF24DDE00D1E4C1 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -107,6 +110,8 @@
818F0B851E18C08100679925 = {
isa = PBXGroup;
children = (
81CFC861202953CB00CF9D83 /* .travis.yml */,
81CFC85F2029456C00CF9D83 /* readme-chs.md */,
81EBBFFD1EF24DDE00D1E4C1 /* README.md */,
81EBBFF71EF246BD00D1E4C1 /* dsBridge.podspec */,
818F0B901E18C08100679925 /* dsbridge */,
Expand Down Expand Up @@ -275,6 +280,7 @@
buildActionMask = 2147483647;
files = (
81EBBFFF1EF24DDE00D1E4C1 /* README.md in Sources */,
81CFC8602029456C00CF9D83 /* readme-chs.md in Sources */,
818F0BC01E18C59200679925 /* JSBUtil.m in Sources */,
818F0BB71E18C3B800679925 /* DWKWebView.m in Sources */,
815612EE202041B000C4F5CD /* DSCallInfo.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions dsbridge/JSBUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ +(NSArray *)allMethodFromClass:(Class)class
//NSLog(@"%@",strName);
[arr addObject:strName];
}
free(methods);
return arr;
}

Expand Down
2 changes: 1 addition & 1 deletion dsbridgedemo/JsApiTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ -(void)onTimer:t{
if(value!=-1){
hanlder([NSNumber numberWithInt:value--],NO);
}else{
hanlder(@"",YES);
hanlder(0,YES);
[timer invalidate];
}
}
Expand Down
1 change: 1 addition & 0 deletions dsbridgedemo/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

function callProgress() {
dsBridge.call("callProgress", function (value) {
if(value==0) value="";
document.getElementById("progress").innerText = value
})
}
Expand Down
Loading

0 comments on commit c76ab5a

Please # to comment.