我在Phonegap框架上为安卓和iOS平台开发移动应用程序。我正在使用一些在Android和iOS中有不同行为的函数。因此,我应该维护两个不同的代码集,还是有其他的替代方案。
对于这样的任务,哪个框架更可取。我目前正在使用Sencha touch。
发布于 2014-09-11 05:19:49
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.)
}https://stackoverflow.com/questions/25763222
复制相似问题