Commit 1ef49150 authored by liujiangnan's avatar liujiangnan

feat: 调用原生方法测试

parent a6c4c931
......@@ -9,9 +9,16 @@ export function initAir(_this) {
_this.log("***成功调用onCourseInScreen***");
});
},
osmoCallback: null,
osmoHandwritingCallback: null,
osmoFingerReadCallback: null,
osmoCallback: function(res){
_this.log(`***成功调用osmoCallback***参数==${res}`);
},
osmoHandwritingCallback: function(res){
_this.log(`***成功调用osmoHandwritingCallback***参数==${res}`);
},
osmoFingerReadCallback: function(res){
_this.log(`***成功调用osmoFingerReadCallback***参数==${res}`);
},
getEngineInfoCallback: null,
onCourseInScreen: null,
}
window.courseware = {
......@@ -73,23 +80,51 @@ export function initAir(_this) {
_this.log(`===成功调用openRecognitionCamera===`);
callback && callback(null);
},
getEngineInfo(callback) {
_this.log(`===成功调用getEngineInfo===`);
// 调用原生获取机器信息
window.air.getEngineInfoCallback = (res) => {
callback && callback(res);
window.air.getEngineInfoCallback = null;
};
this.callOcMethod("getEngineInfo", {});
},
openOsmo() {
_this.log(`===成功调用openOsmo===`);
this.callOcMethod("openOsmo", {});
},
closeOsmo() {
_this.log(`===成功调用closeOsmo===`);
this.callOcMethod("closeOsmo", {});
},
openOsmoHandwriting() {
_this.log(`===成功调用openOsmoHandwriting===`);
this.callOcMethod("openOsmoHandwriting", {});
},
closeOsmoHandwriting() {
_this.log(`===成功调用closeOsmoHandwriting===`);
this.callOcMethod("closeOsmoHandwriting", {});
},
openOsmoFingerRead() {
_this.log(`===成功调用openOsmoFingerRead===`);
this.callOcMethod("openOsmoFingerRead", {});
},
closeOsmoFingerRead() {
_this.log(`===成功调用closeOsmoFingerRead===`);
this.callOcMethod("closeOsmoFingerRead", {});
},
callOcMethod(method, param) {
const paramStr = JSON.stringify(param);
_this.log(`===成功调用原生方法${method}===参数==${paramStr}`);
if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
return jsb.reflection.callStaticMethod('CocosMng', `${method}:`, paramStr);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_ANDROID) {
return jsb.reflection.callStaticMethod('com/iplayabc/cocos/AppActivity', method, '(Ljava/lang/String;)Ljava/lang/String;', paramStr);
} else if (cc.sys.isNative && cc.sys.os == cc.sys.OS_WINDOWS) {
console.log('汪汪汪')
} else {
throw ('非源生环境');
}
},
};
......
......@@ -106,6 +106,14 @@ cc.Class({
this.goPrePage();
});
cc.find('middleLayer/ui/BtnOpenOsmo').on('click', ()=>{
window.courseware.openOsmo();
});
cc.find('middleLayer/ui/BtnCloseOsmo').on('click', ()=>{
window.courseware.closeOsmo();
});
const BtnStartLocal = cc.find('middleLayer/ui/BtnStartLocal');
BtnStartLocal.on('click', () => {
const addressText = cc.find('middleLayer/ui/address');
......
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 to comment