
Java正则表达式通过User-Agent获取IOS版本
如果ios版本为 14_3_1matcher.group(0) 为 CPU iPhone OS 14_3_1 like Mac OSmatcher.group(1) 为 14_3_1matcher.group(2) 为 3_1public Integer getIosVersion(){ServletRequestAttributes attributes = (ServletRequestAtt
·
如果ios版本为 14_3_1
matcher.group(0) 为 CPU iPhone OS 14_3_1 like Mac OS
matcher.group(1) 为 14_3_1
matcher.group(2) 为 3_1
public Integer getIosVersion(){
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String userAgent = request.getHeader("User-Agent");
//region 获取ios大版本 如14 15
Pattern pattern = Pattern.compile("CPU iPhone OS (.*?)_(.*?) like Mac OS");
Matcher matcher = pattern.matcher(userAgent);
Integer iosVersion = null;
if (matcher.find()){
String version = matcher.group(1);
iosVersion = Integer.valueOf(version);
}
//endregion
return iosVersion;
}
更多推荐
所有评论(0)