-#import "JsEchoApi.h"
-#import "dsbridgedemo-Swift.h"
+#import "dsbridge.h"
+
@interface ViewController ()
@end
@@ -17,26 +16,15 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CGRect bounds=self.view.bounds;
- DWKWebView * dwebview=[[DWKWebView alloc] initWithFrame:CGRectMake(0, 25, bounds.size.width, bounds.size.height-25)];
- [self.view addSubview:dwebview];
-
- // register api object without namespace
- [dwebview addJavascriptObject:[[JsApiTest alloc] init] namespace:nil];
-
- // register api object without namespace
- [dwebview addJavascriptObject:[[ JsApiTestSwift alloc] init] namespace:@"swift"];
-
- // register api object with namespace "echo"
- [dwebview addJavascriptObject:[[JsEchoApi alloc] init] namespace:@"echo"];
-
- // open debug mode, Release mode should disable this.
- [dwebview setDebugMode:true];
-
- [dwebview customJavascriptDialogLabelTitles:@{@"alertTitle":@"Notification",@"alertBtn":@"OK"}];
-
- dwebview.navigationDelegate=self;
-
- // load test.html
+ //bounds.origin.y=20;
+ //bounds.size.height-=20;
+ DWebview * webview=[[DWebview alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height-25)];
+ webview.backgroundColor=UIColor.redColor;
+ jsApi=[[JsApiTest alloc] init];
+ webview.JavascriptInterfaceObject=jsApi;
+ [self.view addSubview:webview];
+
+ //加载test.html
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString * htmlPath = [[NSBundle mainBundle] pathForResource:@"test"
@@ -44,67 +32,21 @@ - (void)viewDidLoad {
NSString * htmlContent = [NSString stringWithContentsOfFile:htmlPath
encoding:NSUTF8StringEncoding
error:nil];
- [dwebview loadHTMLString:htmlContent baseURL:baseURL];
-
- // call javascript method
- [dwebview callHandler:@"addValue" arguments:@[@3,@4] completionHandler:^(NSNumber * value){
- NSLog(@"%@",value);
- }];
-
- [dwebview callHandler:@"append" arguments:@[@"I",@"love",@"you"] completionHandler:^(NSString * _Nullable value) {
- NSLog(@"call succeed, append string is: %@",value);
- }];
-
- // this invocation will be return 5 times
- [dwebview callHandler:@"startTimer" completionHandler:^(NSNumber * _Nullable value) {
- NSLog(@"Timer: %@",value);
- }];
-
- // namespace syn test
- [dwebview callHandler:@"syn.addValue" arguments:@[@5,@6] completionHandler:^(NSDictionary * _Nullable value) {
- NSLog(@"Namespace syn.addValue(5,6): %@",value);
- }];
-
- [dwebview callHandler:@"syn.getInfo" completionHandler:^(NSDictionary * _Nullable value) {
- NSLog(@"Namespace syn.getInfo: %@",value);
- }];
-
- // namespace asyn test
- [dwebview callHandler:@"asyn.addValue" arguments:@[@5,@6] completionHandler:^(NSDictionary * _Nullable value) {
- NSLog(@"Namespace asyn.addValue(5,6): %@",value);
- }];
-
- [dwebview callHandler:@"asyn.getInfo" completionHandler:^(NSDictionary * _Nullable value) {
- NSLog(@"Namespace asyn.getInfo: %@",value);
- }];
-
- // test if javascript method exists.
- [dwebview hasJavascriptMethod:@"addValue" methodExistCallback:^(bool exist) {
- NSLog(@"method 'addValue' exist : %d",exist);
+ [webview loadHTMLString:htmlContent baseURL:baseURL];
+ __weak DWebview * _webview=webview;
+ [webview setJavascriptContextInitedListener:^(){
+ [_webview callHandler:@"test"
+ arguments:[[NSArray alloc] initWithObjects:@1,@"hello", nil]
+ completionHandler:^(NSString * value){
+ NSLog(@"%@",value);
+ }];
}];
-
- [dwebview hasJavascriptMethod:@"XX" methodExistCallback:^(bool exist) {
- NSLog(@"method 'XX' exist : %d",exist);
- }];
-
- [dwebview hasJavascriptMethod:@"asyn.addValue" methodExistCallback:^(bool exist) {
- NSLog(@"method 'asyn.addValue' exist : %d",exist);
- }];
-
- [dwebview hasJavascriptMethod:@"asyn.XX" methodExistCallback:^(bool exist) {
- NSLog(@"method 'asyn.XX' exist : %d",exist);
- }];
-
- // set javascript close listener
- [dwebview setJavascriptCloseWindowListener:^{
- NSLog(@"window.close called");
- } ];
-
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
}
diff --git a/dsbridgedemo/dsbridgedemo-Bridging-Header.h b/dsbridgedemo/dsbridgedemo-Bridging-Header.h
deleted file mode 100644
index 1b2cb5d..0000000
--- a/dsbridgedemo/dsbridgedemo-Bridging-Header.h
+++ /dev/null
@@ -1,4 +0,0 @@
-//
-// Use this file to import your target's public headers that you would like to expose to Swift.
-//
-
diff --git a/dsbridgedemo/test.html b/dsbridgedemo/test.html
index 732ba64..50192e1 100644
--- a/dsbridgedemo/test.html
+++ b/dsbridgedemo/test.html
@@ -1,167 +1,85 @@
-
-
- DSBridge Test
-
-
-
-
-
-
-
-
-Synchronous call
-Asynchronous call
-Syn call (swift)
-Async call(swift)
-Sync call without argument
-Async call without argument
-echo.syn
-echo.asyn
-Stress test,2K times consecutive asynchronous API calls
-Never call because without @JavascriptInterface
- annotation
( This test is
- just for Android ,should be ignored in IOS )
-
-call progress
-hasNativeMethod("xx")
-hasNativeMethod("testSyn")
-
-
-
+
+