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-------");
        };
    

      

  • 相关阅读:
    css hack
    使div高度自适应,两列高度一样
    ie8 下使用video 标签的z-index问题
    css 选择器的介绍和兼容性说明
    前端性能优化
    parallax.js插件,使页面随鼠标呈现出层次化的动画效果
    css 绝对定位实现一个轮播效果
    js学习随笔记录
    用js实现的一个小程序(对一块区域的放大,缩小)
    最少步数----深搜
  • 原文地址:https://www.cnblogs.com/studyNT/p/6213045.html
Copyright © 2011-2022 走看看