Phonegap / Cordova App设备检测不适用于iOS

时间:2016-07-28 07:40:41

标签: ios cordova ipad

我是一名年轻的开发人员,他的学校项目在我的学校中传播,然后变成了一个应用程序。我使用的是Phonegap,因为我是网络语言中最先进的。我决定迎合所有设备,但最初是为iPhone布局而构建的。为了让它在iPad上看起来很好,我使用Cordova设备检测来实现我的更改(我知道这很糟糕),如下所示:

//Checks what device is being used
var deviceType = (navigator.userAgent.match(/iPad/i))  == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i))  == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";
//Width & Height for Tannock Image
var width = 178.5;
var height = 270;
//If device is iPad
if(deviceType == "iPad"){ 
$('#teaImg').css('height', '540px');    
$('#teaImg').css('width', '357px');    
$('#text1').css('margin-left', '38%');
$('#text1').css("font-size", '35px');    
width = 357;
height = 270;    
}

当我通过Xcode直接将它送到我的iPad时,这个令人震惊的代码工作得非常好,但是当我从应用程序商店下载它时,它已经不再有效了,所以不是看起来像我想要它,它没有&# 39;应用任何这些变化。

有谁知道如何解决这个问题?

P.s该应用程序被称为Tannock Tapper,我知道它的马车,我是一个单人团队,学校优先考虑。

1 个答案:

答案 0 :(得分:0)

我根据设备修改了我的代码,如下所示:

我以您的格式设置代码供您使用。

var isAndroid = navigator.userAgent.match(/android/i) ? true : false;
var isIPhone = navigator.userAgent.match(/iphone/i) ? true : false;
var isIPad = navigator.userAgent.match(/ipad/i) ? true : false;
var isBlackberry = (navigator.userAgent.match(/BlackBerry/i)) ? true : false; 

var width = 178.5;
var height = 270;

//If device is iPad
if(isIPad){ 
    $('#teaImg').css('height', '540px');    
    $('#teaImg').css('width', '357px');    
    $('#text1').css('margin-left', '38%');
    $('#text1').css("font-size", '35px');    
    width = 357;
    height = 270;    
}

// If device is android
if(isAndroid){
// android related code
}

if(isBlackberry){
// Black berry related code.
}

我的应用程序中也有相同的代码,我在我的应用程序中已经在应用程序商店中使用过去3年的代码。

如果看起来令人困惑,请告诉我。