From b4571e07aa68c36519d078d6af47759a5058bec6 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Mon, 29 Aug 2022 12:25:51 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20=E9=98=B2=E5=91=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Script/Manager.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/assets/Script/Manager.ts b/assets/Script/Manager.ts index c381719..6329ed2 100644 --- a/assets/Script/Manager.ts +++ b/assets/Script/Manager.ts @@ -62,14 +62,19 @@ export default class Manager extends cc.Component { self.Birdge(method, value); }; } - let scheme: string = "jmka"; + let scheme: string = "http"; this.webview.setJavascriptInterfaceScheme(scheme); this.webview.setOnJSCallback((sender: any, url: any) => { - let data: JSON = JSON.parse(decodeURI(url.split(`${scheme}://`)[1])); - let method: any = data["method"]; - let value: any = data["value"]; - if (method) { - self.Birdge(method, ...value); + let content: string = decodeURI(url.split(`${scheme}://`)[1]); + try { + let data: JSON = JSON.parse(content); + let method: any = data["method"]; + let value: any = data["value"]; + if (method) { + self.Birdge(method, ...value); + } + } catch (error) { + console.error(error); } }); }