Commit 1ef49150 authored by liujiangnan's avatar liujiangnan

feat: 调用原生方法测试

parent a6c4c931
...@@ -9,9 +9,16 @@ export function initAir(_this) { ...@@ -9,9 +9,16 @@ export function initAir(_this) {
_this.log("***成功调用onCourseInScreen***"); _this.log("***成功调用onCourseInScreen***");
}); });
}, },
osmoCallback: null, osmoCallback: function(res){
osmoHandwritingCallback: null, _this.log(`***成功调用osmoCallback***参数==${res}`);
osmoFingerReadCallback: null, },
osmoHandwritingCallback: function(res){
_this.log(`***成功调用osmoHandwritingCallback***参数==${res}`);
},
osmoFingerReadCallback: function(res){
_this.log(`***成功调用osmoFingerReadCallback***参数==${res}`);
},
getEngineInfoCallback: null,
onCourseInScreen: null, onCourseInScreen: null,
} }
window.courseware = { window.courseware = {
...@@ -73,23 +80,51 @@ export function initAir(_this) { ...@@ -73,23 +80,51 @@ export function initAir(_this) {
_this.log(`===成功调用openRecognitionCamera===`); _this.log(`===成功调用openRecognitionCamera===`);
callback && callback(null); callback && callback(null);
}, },
getEngineInfo(callback) {
_this.log(`===成功调用getEngineInfo===`);
// 调用原生获取机器信息
window.air.getEngineInfoCallback = (res) => {
callback && callback(res);
window.air.getEngineInfoCallback = null;
};
this.callOcMethod("getEngineInfo", {});
},
openOsmo() { openOsmo() {
_this.log(`===成功调用openOsmo===`); _this.log(`===成功调用openOsmo===`);
this.callOcMethod("openOsmo", {});
}, },
closeOsmo() { closeOsmo() {
_this.log(`===成功调用closeOsmo===`); _this.log(`===成功调用closeOsmo===`);
this.callOcMethod("closeOsmo", {});
}, },
openOsmoHandwriting() { openOsmoHandwriting() {
_this.log(`===成功调用openOsmoHandwriting===`); _this.log(`===成功调用openOsmoHandwriting===`);
this.callOcMethod("openOsmoHandwriting", {});
}, },
closeOsmoHandwriting() { closeOsmoHandwriting() {
_this.log(`===成功调用closeOsmoHandwriting===`); _this.log(`===成功调用closeOsmoHandwriting===`);
this.callOcMethod("closeOsmoHandwriting", {});
}, },
openOsmoFingerRead() { openOsmoFingerRead() {
_this.log(`===成功调用openOsmoFingerRead===`); _this.log(`===成功调用openOsmoFingerRead===`);
this.callOcMethod("openOsmoFingerRead", {});
}, },
closeOsmoFingerRead() { closeOsmoFingerRead() {
_this.log(`===成功调用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({ ...@@ -106,6 +106,14 @@ cc.Class({
this.goPrePage(); 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'); const BtnStartLocal = cc.find('middleLayer/ui/BtnStartLocal');
BtnStartLocal.on('click', () => { BtnStartLocal.on('click', () => {
const addressText = cc.find('middleLayer/ui/address'); 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