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

  

转载于:https://www.cnblogs.com/studyNT/p/6213045.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值