我正在为Phonegap框架上的Android和iOS平台开发移动应用程序。我正在使用一些在Android和iOS中具有不同行为的函数。因此,为此,我应该保留两组不同的代码,或者还有其他替代方法。
哪种框架更适合此类任务。我目前正在使用Sencha touch。
答案 0 :(得分: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.)
}