如何通过用户代理检测iOS 6和所有次要版本? [英] How to detect iOS 6 and all minor versions by user agent?

查看:81
本文介绍了如何通过用户代理检测iOS 6和所有次要版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用简单的正则表达式或其他东西通过用户代理检测iOS 6和所有次要版本?也很好区分iphone和ipad。

How to detect iOS 6 and all minor versions by user agent with a simple regex or something? Would be nice to distinct between iphone and ipad as well.

这个问题与什么是iOS 6用户代理字符串?因为我想要帮助建立一个基于我已经知道的信息(可以在链接的问题中找到)

This question differs from What is the iOS 6 user agent string? since I wanted help in building a regex based on the information I already know (which can be found in the linked question)

推荐答案

CHANGELOG


20/01/2017


  • UA字符串更新:141匹配,0部分匹配,797无效行

  • UA strings update: 141 matching, 0 partially matching, and 797 invalid lines

Mobile Safari 1.1.3(iPhone U; CPU)像Mac OS X; en)即使提到iPhone也被视为无效。实际上在 iPhone 这个术语可疑之后会丢失一个分号。

"Mobile Safari 1.1.3 (iPhone U; CPU like Mac OS X; en)" is considered invalid even if it mentions iPhone. Actually a semi-colon is missing after the iPhone term which is suspicious.

Safari 8+没有在UserAgentString.com上出现

Safari 8+ doesn't appear yet on UserAgentString.com

前提是


  • 以下正则表达式是通用的。

  • 它将匹配Safari用户代理字符串(SUAS)在移动设备上运行(参见下面支持的设备列表)。

  • 正则表达式基于已知的SUAS UserAgentString.com 20/01/2017

  • The following regex is generic.
  • It will match Safari user agent strings (SUAS) running on a mobile device (see below supported devices list).
  • The regex is based on known SUAS by UserAgentString.com as of 20/01/2017.

REGEX

^(?:(?:(?:Mozilla/\d\.\d\s*\()+|Mobile\s*Safari\s*\d+(?:\.\d+)+\s*)(?:iPhone(?:\s+Simulator)?|iPad|iPod);\s*(?:U;\s*)?(?:[a-z]+(?:-[a-z]+)?;\s*)?CPU\s*(?:iPhone\s*)?(?:OS\s*\d+_\d+(?:_\d+)?\s*)?(?:like|comme)\s*Mac\s*O?S?\s*X(?:;\s*[a-z]+(?:-[a-z]+)?)?\)\s*)?(?:AppleWebKit/\d+(?:\.\d+(?:\.\d+)?|\s*\+)?\s*)?(?:\(KHTML,\s*(?:like|comme)\s*Gecko\s*\)\s*)?(?:(?:Version|CriOS)/\d+(?:\.\d+)+\s*)?(?:Mobile/\w+\s*)?(?:Safari/\d+(?:\.\d+)*.*)?$

支持的设备列表


  • iPhone

  • iPhone模拟器

  • iPad

  • iPod

  • iPhone
  • iPhone Simulator
  • iPad
  • iPod

说明/定制

前面带有 C 可以自定义。

Lines preceded by a C can be customized.

  1. ^(?:(?:(?:Mozilla/\d\.\d\s*\()+|Mobile\s*Safari\s*\d+(?:\.\d+)+\s*)
C 2.     (?:iPhone(?:\s+Simulator)?|iPad|iPod);\s*
  3.     (?:U;\s*)?
  4.     (?:[a-z]+(?:-[a-z]+)?;\s*)?
  5.     CPU\s*
  6.          (?:iPhone\s*)?
C 7.          (?:OS\s*\d+_\d+(?:_\d+)?\s*)?
C 8.          (?:like|comme)\s*Mac\s*O?S?\s*X
  9.      (?:;\s*[a-z]+(?:-[a-z]+)?)?
  10. \)\s*)?
  11. (?:AppleWebKit/\d+(?:\.\d+(?:\.\d+)?|\s*\+)?\s*)?
C 12. (?:\(KHTML,\s*(?:like|comme)\s*Gecko\s*\)\s*)?
C 13. (?:(?:Version|CriOS)/\d+(?:\.\d+)+\s*)?
  14. (?:Mobile/\w+\s*)?
  15. (?:Safari/\d+(?:\.\d+)*.*)?$

第1行。 UA字符串可能不同,因此引入此行以尽可能多地接受UA字符串。

第2行。 您可以在此处指定已接受设备的管道分隔列表。

(...)

第7行。指示版本这里。如果需要特殊版本,请更改此行。不要忘记更新第13行。例如,匹配 iOS 5.xy 使用(?:OS \ * * 5_ \d + _ \\\ + + \\ * * *)?

第8行。某些用户代理字符串已翻译。单词可能会被翻译成外语。正则表达式现在支持英语法语。如果您遇到其他语言,请调整此行。不要忘记更新第12行

(...)

第12行。请参阅第8行。

第13行。请参阅第7行。例如,匹配 iOS 5.xy 使用(?:Version / 5 \.\d + \.\d +)?\ * *)?

line 1. UA strings may differ so this line is introduced for accepting UA strings as much as possible.
line 2. You can specify here the piped-separated list of accepted devices.
(...)
line 7. The version is indicated here. Change this line if you want a special version. Don't forget to update line 13 too. For instance, matching iOS 5.x.y use (?:OS\s*5_\d+_\d+\s*)?.
line 8. Some user agent strings are translated. The word like may be translated into a foreign language. The regexp now supports English and French. Adapt this line if you encounter other languages. Don't forget to update line 12 too.
(...)
line 12. See line 8.
line 13. See line 7. For instance, matching iOS 5.x.y use (?:Version/5\.\d+\.\d+)?\s*)?.

这篇关于如何通过用户代理检测iOS 6和所有次要版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆