设为首页 加入收藏

TOP

【Swift】WKWebView与JS的交互使用(五)
2019-08-15 00:11:51 】 浏览:494
Tags:Swift WKWebView 交互 使用
(_ webView: WKWebView, runjava scriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) { let alertVicwController = UIAlertController(title: "提示", message: message, preferredStyle: UIAlertController.Style.alert) alertVicwController.addAction(UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel, handler: { (alertAction) in completionHandler(false) })) alertVicwController.addAction(UIAlertAction(title: "确定", style: UIAlertAction.Style.default, handler: { (alertAction) in completionHandler(true) })) self.present(alertVicwController, animated: true, completion: nil) } // prompt //作为js中prompt接口的实现,默认需要有一个输入框一个按钮,点击确认按钮回传输入值 //当然可以添加多个按钮以及多个输入框,不过completionHandler只有一个参数,如果有多个输入框,需要将多个输入框中的值通过某种方式拼接成一个字符串回传,js接收到之后再做处理 //参数 prompt 为 prompt(<message>, <defaultValue>);中的<message> //参数defaultText 为 prompt(<message>, <defaultValue>);中的 <defaultValue> func webView(_ webView: WKWebView, runjava scriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) { let alertViewController = UIAlertController(title: prompt, message: "", preferredStyle: UIAlertController.Style.alert) alertViewController.addTextField { (textField) in textField.text = defaultText } alertViewController.addAction(UIAlertAction(title: "完成", style: UIAlertAction.Style.default, handler: { (alertAction) in completionHandler(alertViewController.textFields![0].text) })) self.present(alertViewController, animated: true, completion: nil) } }

 

   参考连接:https://mp.weixin.qq.com/s/Tp7WxHXp_0EATIKvSuBhlw

 

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇zap+日志分级分文件+按时间切割日.. 下一篇ubuntu 下 go 语言调试器 dlv 的..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目