如何检测iOS使用Javascript的不同设备?

我正在尝试与Objective C相关的应用程序创buildJavascript 。 我正在UIWebviewUIWebview JavaScript内容页面。 UIWebview内容页面视图我想根据设备模型区分sizesiOS 。 如何使用JavaScript来区分设备检测。

我的代码如下:

  // iPhone 3 if (window.screen.height==480 && window.screen.width==320 && window.devicePixelRatio==1) { $('#chartDivWrapper').html('<div id="chartdiv" style="height:300px;width:500px;"></div>'); } // iPhone 4, this is Retina else if (window.screen.height==480 && window.screen.width==320 && window.devicePixelRatio==2) { $('#chartDivWrapper').html('<div id="chartdiv" style="height:300px;width:500px;"></div>'); } // iPhone 5 else if (window.screen.height==568 && window.screen.width==320 && window.devicePixelRatio==2) { $('#chartDivWrapper').html('<div id="chartdiv" style="height:400px;width:600px;"></div>'); } // iPad else if (window.screen.height==1024 && window.screen.width==768 && window.devicePixelRatio==1) { $('#chartDivWrapper').html('<div id="chartdiv" style="height:425px;width:680px;"></div>'); } // iPad Retina else if (window.screen.height==1024 && window.screen.width==768 && window.devicePixelRatio==2) { $('#chartDivWrapper').html('<div id="chartdiv" style="height:425px;width:680px;"></div>'); } // all other, this was before for all else {