ITPub博客

首页 > > > js调用oc后,执行oc方法(block里面),web数据没变!

js调用oc后,执行oc方法(block里面),web数据没变!

作者:germo 时间:2019-09-06 17:14:29 0 删除 编辑

-(void)webViewDidFinishLoad:(UIWebView *)webView { //saveUser submit

// 初始化content

self.context = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

__weak typeof(self) weakSelf = self;
self.context[@"saveUser"] = ^{
    NSArray *arg = [JSContext currentArguments];
    for (id obj in arg) {
        NSLog(@"obj is:%@", obj);
    }

    //保存 信息
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf.navigationController popViewControllerAnimated:YES];

        //只显示文字
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:APP_SCREENWINDOW animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.label.text = @"保存成功!";
        hud.margin = 10.f;
        hud.offset = CGPointMake(0, 0.f);
        hud.removeFromSuperViewOnHide = YES;
        [hud hideAnimated:YES afterDelay:1.5f];
        hud.userInteractionEnabled = NO;
    });

};

}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1868/viewspace-3160810/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-17

  • 博文量
    209
  • 访问量
    8229