合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# js调用ios方法 ## ios ~~~objectivec // js配置 WKUserContentController *userContentController = [[WKUserContentController alloc] init]; //需要JS调用iOS 原生的方法,都要添加到这里 [userContentController addScriptMessageHandler:self name:@"finishHandle"]; // WKWebView的配置 WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; configuration.userContentController = userContentController; // 显示WKWebView self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-NavitionbarHeight) configuration:configuration]; self.webView.UIDelegate = self; // 设置WKUIDelegate代理 [self.view addSubview:self.webView]; ~~~ ## js ``` js window.webkit.messageHandlers.finishHandle.postMessage('哈哈'); ```