JavaScript 中的 iPad 版本检测
是否可以在 Web 应用程序中检查 iPad 版本(1 或 2)?由于用户代理看起来相同(请参阅 http://www.webtrends。 com/Support/KnowledgeBase/SolutionDetail.aspx?Id=50140000000acbiAAA)标准通过浏览器检查在这里不起作用。
我们可以检查 JavaScript 中仅在版本 2 中可用的功能(如陀螺仪)吗?
Is it possible to check for the iPad version (1 or 2) in a web application? As the user agent looks identical (see http://www.webtrends.com/Support/KnowledgeBase/SolutionDetail.aspx?Id=50140000000acbiAAA) a standard check by browser does not work here.
Can we check for features (like the gyroscope) in JavaScript which are only available in version 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
请尝试这个小提琴。它通过陀螺仪可用性检测 iPad 的版本。
正如您在 Safari 开发者库中看到的,
event.acceleration
在具有陀螺仪的设备上不为空。由于 iPad 1 没有,我们可以假设该设备是 iPad 1。为了区分 iPad 2 和 iPad 3,我们可以检查
window.devicePixelRatio
属性,因为 iPad 3 具有 Retina 显示屏像素比 == 2。Please try this fiddle. It detects version of iPad by gyroscope availability.
As you can see in Safari Developer Library,
event.acceleration
is not null on devices that has a gyroscope. Since iPad 1 doesn't has it, we can assume that this device is iPad 1.To distinguish iPad 2 from iPad 3, we can check a
window.devicePixelRatio
property, since iPad 3 has Retina display with pixel ratio == 2.抱歉,目前 iPad 和 iPad 2 之间没有区别。看,两者之间没有区别:请注意,版本 iOS 更新不断变化。
更新
看起来它们之间有区别:
Sorry but currently there is no difference between iPad and iPad 2.See, there is no difference between the two of them:And notice there, that the versions there are constantly changing in iOS updates.
UPDATE
Looks like there is a difference between them:
这个有点晚了,但是通过使用 WEBGL_debug_renderer_info 扩展,它是 WebGL 的一部分API,您可以检索GPU的供应商和渲染器名称。
将此与设备的屏幕尺寸相结合,您可以准确地定义它是哪个版本。
它也可以针对 iPhone 型号完成,此博客 进入更多细节。
Bit late to this one but by using WEBGL_debug_renderer_info extension, which is part of the WebGL API, you are able to retrieve the vendor of the GPU and the renderer name.
Combining this with screen dimensions of the device you can accurately define which version it is.
It can also be done for iPhone models, this blog goes into more detail.
在 iPad 1 和 2 之间检测 步骤:
在 iPad 2 和 3 之间检测 步骤:
在 iPad 3 和 4 之间检测 步骤:
最大值各向异性为 16 通常表明现代设备具有良好的图形性能。
Detect between iPad 1 and 2 Steps:
Detect between iPad 2 and 3 Steps:
Detect between iPad 3 and 4 Steps:
Maximum Anisotropy of 16 usually indicates a modern device with decent graphics performance.
正如其他人已经指出的那样,这些是当前使用的 2 个用户代理:
但是如果您仔细观察,它们不相同,有一个区别:
所以,就这样。
As others have already pointed out, these are the 2 useragent currently in use:
But if you look close enough, they are not the same, there's a difference:
So, there you go.
用户代理检测会为您提供 Safari 应用程序的版本,而不是 iPad 本身的版本,因为您的 Web 应用程序只能在浏览器环境中运行。
陀螺仪和所有其他 API 都是 SDK API,因此它们仅适用于本机应用程序开发,不适用于 Web 应用程序。
The user agent detection gets you the version of the Safari app, not the version of the iPad itself because your web app will only run in the browser environment.
The gyroscope and all other API's are SDK API's so they are only available for native app development, not for web apps.
看起来 iPad 2 可以具有与新 iPad 相同的 Mobile/9B176 代码。也许是因为iOS更新了?
这是我完整的 iPad2 用户代理字符串:
Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3
我无法检查更新的 iPad 3。有人可以告诉我是否有什么不同吗?
(顺便说一下,如果你只是想知道用户使用的是低分辨率还是高分辨率的 iPad,你可以使用这个技巧:https://stackoverflow.com/a/10142357/974563)
looks like the iPad 2 can have the same Mobile/9B176 code than the New iPad. Maybe it's because of an update of iOS?
Here is my full iPad2 user-agent string:
Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3
I can't check on an updated iPad 3. Could someone please tell me if there is any difference?
(by the way, if you just want to know if the user has a low-res or a high-res iPad, you can use this trick: https://stackoverflow.com/a/10142357/974563 )
请不要依赖用户代理字符串解释。
这根本不可靠:我可以在 iPad2 上看到 Mobile/8J2,在 iPad1 上看到 Mobile/9A405。因此,不同的 iOS 版本(以及 Safari)会在同一 iPad 版本上提醒不同的 UA。
我们应该只进行加速特征检测;客户端或服务器端(WURFL 加速等... )。
PLS DON'T RELY ON User-Agent STRING INTERPRETATION.
This is not reliable at all: I can see Mobile/8J2 on iPad2 and Mobile/9A405 on iPad1. So different iOS versions(and thus Safari) alert different UA on the same iPad version.
We should go with acceleration feature detection only; either client-side or server-side (WURFL acceleration etc...).
怎么样:
另外,看看这个:
http://davidwalsh.name/detect-ipad
How about:
Also, check out this:
http://davidwalsh.name/detect-ipad