美文网首页
js调原生IOS方法传参

js调原生IOS方法传参

作者: 蜗牛1992 | 来源:发表于2019-05-07 12:08 被阅读0次

    防止遗忘,简单记录下。

    //H5
    if (
        ('undefined' != typeof(window.Android) &&
                                    null != window.Android &&
                                    'undefined' != typeof(window.Android.joinConfereanceWithConferId) &&
                                    null != window.Android.joinConfereanceWithConfRoomMarkPassword
                                ) || (
                                    'undefined' != typeof(window.LINKCAREIOS) &&
                                    null != window.LINKCAREIOS &&
                                    'undefined' != typeof(window.LINKCAREIOS.joinConfereanceWithConferId) &&
                                    null != window.LINKCAREIOS.joinConfereanceWithConfRoomMarkPassword
                                )
                            ) {
                                $(".mui-btn-warning").on("tap", function() {
                                    event.stopPropagation();
                                    var ua = navigator.userAgent.toLowerCase();
                                    if (/android/.test(ua)) { //安卓                                  
                                        window.Android.joinConfereanceWithConfRoomMarkPassword(tempConf.conferid,'password');
                                    } else if (/iphone/.test(ua) || /ipad/.test(ua)) { //苹果
                                        window.LINKCAREIOS.joinConfereanceWithConfRoomMark(tempConf.conferid,tempConf.psw);
                                    }
                                });
                            } else {
                                //非手机点击
                                $(".mui-btn-warning").on("tap", function() {
                                    event.stopPropagation();
                                    alert('非手机点击加入会议,conferid='+tempConf.conferid);
                                });
                            }   
    //IOS
    #import <JavaScriptCore/JavaScriptCore.h>
    @protocol SchedeleJSObjDelegate <JSExport>
    - (void)joinConfereanceWithConfRoomMark: (NSString *)conferRoomMark Password:(NSString *)psw;
    @end
    
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView{
        //首先创建JSContext 对象(此处通过当前webView的键获取到jscontext)
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        self.jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
        self.jsContext[@"LINKCAREIOS"] = self;
        self.jsContext.exceptionHandler = ^(JSContext *context, JSValue *ex){
            context.exception = ex;
            NSLog(@"异常信息%@",ex);
        };
    }
    - (void)joinConfereanceWithConfRoomMark: (NSString *)conferRoomMark Password:(NSString *)psw{
    
    

    相关文章

      网友评论

          本文标题:js调原生IOS方法传参

          本文链接:https://www.haomeiwen.com/subject/iatqnqtx.html