Skip to content

getInnerVersion

描述

从 UserAgent 中提取内部版本号。该函数通过解析 UserAgent 字符串中的 innerversion 字段来获取应用的内部版本信息,通常用于版本比较和兼容性检查。

语法

ts
getInnerVersion(): string | false

参数

返回值

  • string: 内部版本号字符串(如 "iosv1.2.3", "andv2.1.0")
  • false: 如果未找到内部版本号

示例

基本用法

ts
import { getInnerVersion } from '@fu/matrix';

// 在 iOS 应用中
// UserAgent: "iHexin/10.80.60 (iPhone; innerversion/iosv1.2.3) WebKit/537.36"
const version = getInnerVersion();
console.log(version); // => "iosv1.2.3"

// 在 Android 应用中
// UserAgent: "IHexin_Futures/8.90.50 (Android; innerversion/andv2.1.0) WebKit/537.36"
const version = getInnerVersion();
console.log(version); // => "andv2.1.0"

版本检查

ts
import { getInnerVersion } from '@fu/matrix';

const version = getInnerVersion();
if (version) {
  console.log(`当前内部版本: ${version}`);
  
  // 根据版本号进行不同的处理
  if (version.startsWith('iosv')) {
    console.log('iOS 版本');
  } else if (version.startsWith('andv')) {
    console.log('Android 版本');
  }
} else {
  console.log('未找到内部版本号');
}

与其他函数配合使用

ts
import { getInnerVersion, isHigherInnerVersion } from '@fu/matrix';

const currentVersion = getInnerVersion();
if (currentVersion) {
  console.log(`当前版本: ${currentVersion}`);
  
  // 检查是否满足最低版本要求
  const isSupported = isHigherInnerVersion({
    ios: '1.2.0',
    android: '2.0.0'
  });
  
  if (isSupported) {
    console.log('版本满足要求');
  } else {
    console.log('版本过低,需要更新');
  }
}

环境判断

ts
import { getInnerVersion } from '@fu/matrix';

function checkAppEnvironment() {
  const version = getInnerVersion();
  
  if (!version) {
    console.log('非应用环境或无版本信息');
    return;
  }
  
  // 检查是否为开发版本
  if (version.includes('dev') || version.includes('beta')) {
    console.log('开发或测试版本');
  } else {
    console.log('正式版本');
  }
}

版本号格式说明

常见格式

  • iOS 版本: iosv1.2.3
  • Android 版本: andv2.1.0
  • 数字版本: 123
  • 预发布版本: beta-1.0.0-rc.1

解析规则

  1. 函数会查找 UserAgent 中的 innerversion 字段
  2. 支持 /=、空格等多种分隔符
  3. 遇到空格、分号、括号等字符时停止解析
  4. 返回提取的版本号字符串

使用场景

  • 版本兼容性检查: 确保功能在特定版本中可用
  • 功能降级: 根据版本提供不同的功能实现
  • 调试信息: 在日志中记录版本信息
  • 统计分析: 分析不同版本的使用情况

注意事项

  • 该函数依赖于 UserAgent 的格式,不同应用可能有不同的格式
  • 在非浏览器环境中可能返回 false
  • 版本号格式可能随应用更新而变化

相关方法

版本历史

  • v1.3.0: 初始版本