2014-09-10 69 views
0

我正在Phonegap框架上爲Android和iOS平臺開發移動應用程序。我正在使用一些在Android和iOS中具有不同行爲的函數。所以爲此我應該保留2套不同的代碼,或者有其他一些替代方案。Phonegap中不同平臺的不同底座

哪個框架更適合這樣的任務。我目前使用Sencha觸摸。

回答

0

device插件和if/switch聲明是你的朋友。

$ cordova plugin add org.apache.cordova.device 

然後(之後接收deviceready):

var currentPlatform = "unknown"; 
if (typeof device !== "undefined") { 
    currentPlatform = device.platform.toLowerCase(); 
} 
switch (currentPlatform) { 
    case "android": 
     // do android stuff 
     break; 
    case "ios": 
     // do iOS stuff 
     break; 
    . 
    . // repeat for platforms you need // 
    . 
    default: 
     // default is technically optional here, but might be useful if you have some 
     // fallback that could work on other platforms. Good for throwing an error 
     // if running on an unsupported platform for some odd reason or for supporting 
     // mobile + desktop during development (could have mock data here or mock 
     // operations, etc.) 
}