Commit 1f5e5b30 by huangzhicong

自定义传输的转码方式

parent 965161e8
...@@ -45,14 +45,14 @@ class WebViewProxy( ...@@ -45,14 +45,14 @@ class WebViewProxy(
filesToBase64(method, result, uris, "data:video/mp4") filesToBase64(method, result, uris, "data:video/mp4")
fun <T> success(method: String, result: Result<T>, data: T? = null) { fun <T> success(method: String, result: Result<T>, data: T? = null) {
val json = gson.toJson(result.apply { success(data) }) val json = gson.toJson(result.apply { success(data) }).encode()
webView.evaluateJavascript("javascript:__maxrockyWebViewJavascriptBridgeCallBack__('$method', '$json')", null) webView.evaluateJavascript("javascript:__maxrockyWebViewJavascriptBridgeCallBack__('$method', '$json')", null)
} }
fun <T> failed(method: String, result: Result<T>, msg: String) = failed(method, result, msg, null) fun <T> failed(method: String, result: Result<T>, msg: String) = failed(method, result, msg, null)
fun <T> failed(method: String, result: Result<T>, msg: String, data: T? = null) { fun <T> failed(method: String, result: Result<T>, msg: String, data: T? = null) {
val json = gson.toJson(result.apply { failed(msg, data) }) val json = gson.toJson(result.apply { failed(msg, data) }).encode()
webView.evaluateJavascript("javascript:__maxrockyWebViewJavascriptBridgeCallBack__('$method', '$json')", null) webView.evaluateJavascript("javascript:__maxrockyWebViewJavascriptBridgeCallBack__('$method', '$json')", null)
} }
...@@ -117,4 +117,6 @@ class WebViewProxy( ...@@ -117,4 +117,6 @@ class WebViewProxy(
} }
} }
} }
private fun String.encode() = this.replace("\\", "\\\\").replace("/", "\\/").replace("\"", "\\\"")
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment