[add] iOS Android特別處理

This commit is contained in:
建喵 2022-08-25 17:49:29 +08:00
parent 6cb232192e
commit 62093148f3
5 changed files with 78 additions and 5 deletions

View File

@ -35,7 +35,9 @@ export default class Manager extends cc.Component {
let data: any = e.data;
let method: string = data.method;
let value: any = data.value;
if (method) {
self.Birdge(method, ...value);
}
}, false);
if (!window["Bridge"]) {
@ -43,14 +45,23 @@ export default class Manager extends cc.Component {
self.Birdge(method, value);
};
}
let scheme: string = "jmka";
this.webview.setJavascriptInterfaceScheme(scheme);
this.webview.setOnJSCallback((sender, url) => {
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 href: string = window.location.href;
let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/Test/?host=${href}&v=${Date.now()}`;
// let url: string = `https://karolchang.github.io/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`;
// let url: string = `http://220.134.195.1/public/bonus_casino/html5/jianmiau/BJ_Casino_Rank/?v=${Date.now()}`;
// let url: string = `http://karol.jianmiau.cf/jm-expense-vue-ts/?v=${Date.now()}`;
let url: string = `https://jm-expense-2022.firebaseapp.com/login?v=${Date.now()}`;
// let url: string = `https://jm-expense-2022.firebaseapp.com/login?host=${href}&v=${Date.now()}`;
this.webview.url = url;
// this.webview.url = `http://localhost:8080/jm-expense-vue-ts/?host=${href}&ignore=${Date.now()}`;
this.webview.node.active = true;
cc.view.setResizeCallback(this._resize.bind(this));

View File

@ -1,3 +1,5 @@
// import Text_to_Speech from "./Text_to_Speech";
const { ccclass } = cc._decorator;
@ccclass
@ -17,6 +19,12 @@ export default class NativeClass extends cc.Component {
//#endregion
//#region private
// private _text_to_Speech: Text_to_Speech;
//#endregion
//#region Lifecycle
constructor() {
@ -27,6 +35,7 @@ export default class NativeClass extends cc.Component {
private init(): void {
let self: this = this;
// this._text_to_Speech = new Text_to_Speech();
let HttpData: any[] = [];
// let HttpParmData: any[] = [];
// 註冊要被Java、OC呼叫的事件
@ -135,6 +144,7 @@ export default class NativeClass extends cc.Component {
}
case cc.sys.OS_ANDROID: {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "TTS_Play", "(Ljava/lang/String;)V", msg);
// this._text_to_Speech.speak(msg);
break;
}

View File

@ -1,6 +1,7 @@
{
"ver": "1.0.8",
"ver": "1.1.0",
"uuid": "5558f747-ed9e-4040-9a01-3b89b99ac37a",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,

View File

@ -0,0 +1,41 @@
const responsiveVoice = window["responsiveVoice"];
export default class Text_to_Speech {
//#region 外調參數
private voice: string = null;
//#endregion
//#region Custom
constructor() {
let self: this = this;
responsiveVoice.init();
var voicelist = responsiveVoice.getVoices();
this.setDefaultVoice(voicelist[14].name);
}
public setDefaultVoice(voice: string): void {
this.voice = voice;
responsiveVoice.setDefaultVoice(voice);
}
public speak(msg: string): void {
let self: this = this;
if (responsiveVoice.voiceSupport()) {
responsiveVoice.speak(msg, this.voice, {
onstart: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
onend: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
});
} else {
console.error(`!responsiveVoice.voiceSupport`);
}
}
//#endregion
}

View File

@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "59151148-7427-4d5f-a981-41c6adb57700",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}