Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • D Document
  • Project information
    • Project information
    • Activity
    • Members
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Wiki
    • Wiki
  • Activity
Collapse sidebar
  • SRP_MobileAPP_FrameworkSRP_MobileAPP_Framework
  • Document
  • Wiki
  • Manual
  • jsInterfaceSetting

jsInterfaceSetting · Changes

Page history
add pages authored Feb 20, 2019 by Yuying.Lo's avatar Yuying.Lo
Hide whitespace changes
Inline Side-by-side
manual/jsInterfaceSetting.md 0 → 100644
View page @ 3ca52010
## Communication between iOS/Android native app and webpage Javascript
### From Javascript to iOS/Android
在網頁加入下方 Javascript 來傳遞資訊給 iOS/Android native app
(以 Dashboard 頁面中提供的 changeDashboard API 為範例)
(function (global) {
if (global.callNativeInterface) {
return;
}
function callIosNativeApp (funcName, msg) {
var iosMsg = JSON.stringify({"funcName":funcName, "msg":msg});
try {
console.log('call ios native');
if(webkit && webkit.messageHandlers && webkit.messageHandlers.callIosNativeApp){
webkit.messageHandlers.callIosNativeApp.postMessage(iosMsg);
}
} catch(err){
console.log('The ios native context does not exist yet');
}
}
var callNativeInterface = new Object();
callNativeInterface.changeDashboard = function(type, dashboardUrl){
var cbObj = {};
cbObj.type = type;
cbObj.dashboard = dashboardUrl;
var cbJsonStr = JSON.stringify(cbObj);
if(typeof(appJsInterface) != 'undefined'){
//android
appJsInterface.changeDashboard(cbJsonStr);
}else{
//ios
callIosNativeApp('changeDashboard', cbJsonStr);
}
};
global.callNativeInterface = callNativeInterface;
})(this);
### From iOS/Android to Javascript
在網頁加入下方 Javascript 來接收 iOS/Android native app 傳送的資訊
(以 Dashboard 頁面中提供的 openDialog API 為範例)
(function (global) {
if (global.jsAppInterface) {
return;
}
var jsAppInterface = new Object();
jsAppInterface.messageHandler = function(result){
try{
var resultObj = JSON.parse(result);
var funcName = resultObj.funcName;
var msgObj = resultObj.msg;
if(funcName == 'openDialog'){
if(msgObj.name == 'LSVA'){
// open LSVA dialog
}
}
}catch(error){
console.log(error.message);
}
};
global.jsAppInterface = jsAppInterface;
})(this);
Clone repository
  • SDS
    • SDS
    • tab
      • dashboard
        • api
          • changeDashboard
          • changeDashboardControllerStatus
          • closeDialog
          • getDashboardDomain
          • getDashboardMenu
          • openDialog
        • dashboard
  • Home
  • manual
    • Home
    • image
      • icon
        • ios
          • appIconIos
      • launch
        • ios
          • appLaunchIos
    • jsInterfaceSetting
    • sample
    • sampleAPM
View All Pages