2011-11-17 23 views
0

Chrome的Ripple插件模擬了大部分的PhoneGap API,但我使用的是第三方軟件,使用的API如PhoneGap.exec ()和PhoneGap.stringify(),並且據我所見,我沒有在Ripple環境中獲得它們。Ripple Phone Gap仿真器 - 諸如exec()和stringify()之類的方法

我的解決方法是在初始化的後期階段將這些方法破譯到PhoneGap中。這似乎工作,但感覺像一個kluge。

問題:

1)。 Ripple中有這樣的API可用嗎? 2)。任何建議一個清潔的解決辦法?

回答

1

我認爲如果你正在談論邊緣的波紋,波紋仍然處於測試模式。我以前在使用rim html5的實現時知道,有一個配置文件,您可以在其中指定可以從手機使用的服務....也許在同一個配置文件中,您可以指定某些方法,關鍵是找到該紋波的實現配置文件,並檢查該選項是否存在...

+0

感謝,據我所知,我使用的版本根本沒有缺少方法的代碼。 – djna

0

看着代碼我發現,當PhoneGap想調用一個插件漣漪捕獲最後一次調用(exec方法)並覆蓋本機實現與它的一個。

這是紋波代碼:

var _prompt = ripple('ui/plugins/exec-dialog'), 
emulator = { 
    "App": ripple('platform/cordova/2.0.0/bridge/app'), 
    "Accelerometer": ripple('platform/cordova/2.0.0/bridge/accelerometer'), 
    "Battery" : ripple('platform/cordova/2.0.0/bridge/battery'), 
    "Compass": ripple('platform/cordova/2.0.0/bridge/compass'), 
    "Camera": ripple('platform/cordova/2.0.0/bridge/camera'), 
    ... 
}; 
module.exports = { 
    add: function (service, module) { 
     emulator[service] = module; 
    }, 
    exec: function (success, fail, service, action, args) { 
     try { 
      emulator[service][action](success, fail, args); 
     } 
     catch (e) { 
      console.log("missing exec:" + service + "." + action); 
      console.log(args); 
      console.log(e); 
      console.log(e.stack); 

     _prompt.show(service, action, success, fail); 
     } 
    } 
}; 

,所以我讓我的使用插件之前,這個調用:

ripple('platform/cordova/2.0.0/bridge').add("ToggleBluetooth", { 
                     start: function(){ 
                      console.log("this is a native method call emulation"); 
                      return true; 
                     }, 
                     stop: function(){ 
                      console.log("this is a native method call emulation"); 
                      return true; 
                     } 
                    } 
                   ); 

這樣紋波知道該怎麼辦拋出異常代替。

我使用的是波紋0.9.23