【问题标题】:Phonegap/Cordova App device detection isn't working on iOSPhonegap/Cordova App 设备检测在 iOS 上不起作用
【发布时间】:2016-12-02 11:16:07
【问题描述】:

我是一名年轻的开发人员,他的学校项目在我的学校中风靡一时,然后变成了一个应用程序。我正在使用 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 时,这个令人震惊的代码工作得非常好,但是当我从应用商店下载它时,它不再工作了,所以它看起来不像我想要的那样,它没有t 应用任何这些更改。

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

P.s 这个应用叫做 Tannock Tapper,我知道它有问题,我是一个人的团队,学校优先。

【问题讨论】:

  • 老兄,这是你的代码吗?那么你忘记以 "}" 结束 if 条件。请更新正确的代码。

标签: ios cordova ipad


【解决方案1】:

我根据以下设备修复了我的代码:

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

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 年的代码,该代码已经在应用程序商店中。

如果看起来令人困惑,请联系我。

【讨论】:

  • 嘿,谢谢,希望这会奏效,但我没有办法测试它,只能发布应用程序的更新,我应该如何测试它,就像我将它从 Xcode 馈送到我的 iPad 时一样,它给了我不同的结果,因此我无法查看它是否有效。
  • 来自您 ipad 中的 xcode 的结果是什么,有什么错误或什么?
  • 不,不是你的版本或我的版本,我从platforms/ios获取xcodeproj文件。我是对的?
  • 是的,只需双击默认值,它将在 xcode 中打开
  • 是的,我已经这样做了,但是在我的iPad上模拟的时候没有错误,但是当我从应用商店下载它时,出现错误
猜你喜欢
  • 2020-09-24
  • 1970-01-01
  • 2017-05-15
  • 1970-01-01
  • 1970-01-01
  • 2017-06-22
  • 2017-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多