zoukankan      html  css  js  c++  java
  • h5 与app交互

     

    http://www.jianshu.com/p/7151987f012d

     

    JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
        JSTextObject * jsiOSObject = [JSTextObject new];
        context[@"jsTextObject"] = jsiOSObject;
        
        NSString *jsStr1=@"jsTextObject.CalliOSFunction()";
        JSValue *value1 = [context evaluateScript:jsStr1];
        DDLogInfo(@"the value 1 is %@", value1);
        
        NSString *jsStr2=@"jsTextObject.CalliOSFunctionParamter('hello')";
        JSValue *value2 = [context evaluateScript:jsStr2];
        DDLogInfo(@"the value 1 is %@", value2);
    
        context[@"test1"] = ^() {
            NSArray *args = [JSContext currentArguments];
            for (id obj in args) {
                NSLog(@"test1 %@",obj);
            }
        };
        
        
        context[@"share"] = ^() {
            NSLog(@"+++++++Begin Log+++++++");
            NSArray *args = [JSContext currentArguments];
            
    //        dispatch_async(dispatch_get_main_queue(), ^{
    //            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"方式二" message:@"这是OC原生的弹出窗" delegate:self cancelButtonTitle:@"收到" otherButtonTitles:nil];
    //            [alertView show];
    //        });
            
            NSString *title = @"";
            for (JSValue *jsVal in args) {
                if ([title isEqualToString:@""]) {
                    title = jsVal.toString;
                }
                NSLog(@"%@", jsVal.toString);
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"方式二" message:title delegate:self cancelButtonTitle:@"收到" otherButtonTitles:nil];
                [alertView show];
            });
            
            
            NSLog(@"-------End Log-------");
        };
    

      

  • 相关阅读:
    关于findViewById返回空指针的错误
    android客户端向服务器发送图片和文字,类似于发微博。能用json格式发送吗?
    nodejs 学习资料大全
    篇章三:[AngularJS] 使用AngularCSS動態載入CSS
    篇章二:[AngularJS] 使用AngularAMD動態載入Service
    篇章一:[AngularJS] 使用AngularAMD動態載入Controller
    Angular 资料大集合
    js-音乐播放器,播放|暂停|滑块的功能
    JS-以鼠标位置为中心的滑轮放大功能demo1
    使用 Electron 构建桌面应用(拖动控制篇)
  • 原文地址:https://www.cnblogs.com/studyNT/p/6213045.html
Copyright © 2011-2022 走看看