ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 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('哈哈'); ```