XuqmGroup-RNSDK/packages/update
XuqmGroup 4d2b834f96 feat(sdk): 下载相册/进度、XWebView内联config、上报限频采样、版本忽略、push桥接原生sdk-push
- xwebview: 下载支持公共Downloads/相册(CameraRoll懒加载)/JS进度/openFile;XWebViewView 新增内联 config prop(同屏多实例不污染全局)
- bugcollect: startCapture 自动启用 HttpInterceptor + 按指纹滑动窗口限频 + setSampleRate 采样(降低服务端存储压力)
- update: ignoreAppVersion/clearIgnoredAppVersion/getIgnoredAppVersion 客户端忽略版本(强制更新除外)
- common/metro: withXuqmConfig 自动链式 withBugCollect(Release 包 sourcemap 自动上传)
- push: 桥接完整原生 sdk-push(Android Kotlin + iOS Swift + JS 薄层),删除旧反射实现;单一 XuqmSDK.setUserInfo 驱动厂商检测/token/绑定

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 17:50:29 +08:00
..
android feat: T-B01~B04 — XuqmBundleModule + onProgress + JSBridge/厂商文档 2026-06-15 02:36:11 +08:00
ios feat: T-B01~B04 — XuqmBundleModule + onProgress + JSBridge/厂商文档 2026-06-15 02:36:11 +08:00
scripts feat: v0.3.0 — 自动初始化 + 插件更新 + 脚手架工具 2026-06-15 01:44:20 +08:00
src feat(sdk): 下载相册/进度、XWebView内联config、上报限频采样、版本忽略、push桥接原生sdk-push 2026-06-25 17:50:29 +08:00
package.json fix: @xuqm/rn-common 从 dependencies 移到 peerDependencies,避免宿主项目嵌套安装旧版 2026-06-16 13:27:23 +08:00
react-native.config.js chore: sync local changes 2026-05-07 19:39:41 +08:00
README.md feat: xwebview handleDownloadRequest + README 更新 2026-06-16 13:25:46 +08:00

@xuqm/rn-update

XuqmGroup RN SDK 更新模块。提供 App 整包更新检查和 RN 插件热更新能力。

安装

yarn add @xuqm/rn-update @react-native-async-storage/async-storage

Peer dependenciesreact-native >= 0.76@react-native-async-storage/async-storage >= 1.21.0

快速开始

import { UpdateSDK } from '@xuqm/rn-update'

// 注册插件
UpdateSDK.registerPlugins([
  { moduleId: 'szyx' },
  { moduleId: 'miniapp' },
])

// 注入宿主 BundleRuntime
UpdateSDK.setBundleCallbacks({
  writeBundle: writeBundleFile,
  reloadBundle: loadBundle,
})

// 检查 App 更新
const info = await UpdateSDK.checkAppUpdate()
if (info.needsUpdate) {
  await UpdateSDK.downloadAndInstallApk(info.downloadUrl)
}

// 检查插件更新
const pluginInfo = await UpdateSDK.checkPluginUpdate('szyx')
if (pluginInfo.needsUpdate) {
  await UpdateSDK.updatePlugin('szyx', { onProgress: setProgress })
}

API

插件注册

API 说明
UpdateSDK.registerPlugins(plugins) 批量注册插件
UpdateSDK.registerPlugin(meta) 单个注册(向后兼容)
UpdateSDK.setBundleCallbacks(callbacks) 注入宿主写入/重载能力
UpdateSDK.getRegisteredPlugins() 获取已注册插件列表

App 整包更新

API 说明
UpdateSDK.checkAppUpdate(bypassIgnore?) 检查 App 更新30 分钟缓存)
UpdateSDK.downloadApk(info, options?) 下载 APK,返回 ArrayBuffer支持进度回调
UpdateSDK.downloadAndInstallApk(url, options?) 下载 APK 并调起系统安装器Android
UpdateSDK.openStore(appStoreUrl?, marketUrl?) 跳转应用商店
UpdateSDK.getAppVersionCode() 获取当前 versionCode
UpdateSDK.getAppVersionName() 获取当前 versionName

插件热更新

API 说明
UpdateSDK.checkPluginUpdate(moduleId) 检查插件更新30 分钟缓存)
UpdateSDK.downloadPlugin(moduleId, info, options?) 下载插件 bundle,返回 JS 源码(支持进度回调)
UpdateSDK.updatePlugin(moduleId, options?) 一步完成:检查 → 下载 → 写文件 → 重载

类型定义

interface PluginRegistration {
  moduleId: string
}

interface AppUpdateInfo {
  needsUpdate: boolean
  versionName?: string
  versionCode?: number
  downloadUrl?: string
  changeLog?: string
  forceUpdate?: boolean
  appStoreUrl?: string
  marketUrl?: string
  apkHash?: string | null
}

interface PluginUpdateInfo {
  needsUpdate: boolean
  latestVersion: string
  currentVersion: string
  downloadUrl: string
  md5: string
  minCommonVersion: string
  note: string
  forceUpdate?: boolean
}

interface CachedRnBundle {
  moduleId: string
  version: string
  md5: string
  downloadedAt: string
  source: string
}

type UpdateDownloadProgress = {
  bytesDownloaded: number
  totalBytes: number
  /** 0-100 */
  percent: number
}

下载进度回调

downloadApk()downloadPlugin() 支持 onProgress 回调,使用 fetch + ReadableStream 实现流式进度计算:

// 下载 APK 带进度
const buffer = await UpdateSDK.downloadApk(info, {
  onProgress: ({ bytesDownloaded, totalBytes, percent }) => {
    console.log(`下载进度: ${percent}% (${bytesDownloaded}/${totalBytes})`)
  },
})

// 下载插件 bundle 带进度
const source = await UpdateSDK.downloadPlugin('szyx', pluginInfo, {
  onProgress: ({ percent }) => setProgress(percent),
})

工作原理

  • 版本号由 SDK 自动从本地 AsyncStorage 缓存读取,首次为 0.0.0
  • 更新检查结果缓存 30 分钟TTL,避免频繁请求
  • updatePlugin() 内部自动完成:checkPluginUpdatefetch(downloadUrl) → AsyncStorage 缓存 → writeBundlereloadBundle
  • silent: true 时跳过 reloadBundle,下次启动生效