码迷,mamicode.com
首页 > 移动开发 > 详细

h5 与app交互

时间:2016-12-22 22:45:38      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:begin   color   show   info   style   highlight   object   on()   alt   

 

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

  

h5 与app交互

标签:begin   color   show   info   style   highlight   object   on()   alt   

原文地址:http://www.cnblogs.com/studyNT/p/6213045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!