Getting Started
复制一个包含安装步骤和此插件的完整Markdown指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-webview-version-checker`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/webview-version-checker/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题为“安装”您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-version-checker` plugin in my project.如果您prefer手动设置,安装插件并运行以下命令并遵循以下平台特定的说明:
-
安装包
终端窗口 bun add @capgo/capacitor-webview-version-checker -
同步本机项目
终端窗口 bunx cap sync -
可选:添加插件配置 您可以使用默认值 (
WebviewVersionChecker: {}) 或自定义提示和阈值行为在capacitor.config.ts.
默认行为(主要用例)
标题为“默认行为(主要用例)”默认情况下,这个插件使用一个Browserslist-style兼容性规则:
minimumDeviceSharePercent默认值为3- 共享数据集在构建时从caniuse数据中打包
- 无需为默认流程调用运行时数据集URL
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: {}, },};
export default config;简单配置设置(显示原生提示)
标题:简单配置设置(显示原生提示)import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: { autoPromptOnOutdated: true, }, },};
export default config;高级阈值模式(自定义数据集)
标题:高级阈值模式(自定义数据集)import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: { minimumDeviceSharePercent: 3, versionShareByMajor: { '137': 58.2, '136': 21.3, '135': 4.6, '134': 2.1, }, autoPromptOnOutdated: true, }, },};
export default config;仅在您希望兼容性基于现实世界的分享而不是仅固定版本时使用。
minimumDeviceSharePercent: 3表示安装的主要版本必须代表您的数据集中的至少 3%。versionShareByMajor是您的自定义映射:主要版本 => 百分比。- 如果您更喜欢远程数据,请使用
versionShareApiUrl与以下之一:{ "versionShareByMajor": { "137": 54.2, "136": 23.8 } }{ "shareByMajor": { "137": 54.2, "136": 23.8 } }{ "versions": [{ "major": 137, "share": 54.2 }, { "version": "136.0.0.0", "percent": 23.8 }] }
使用 JavaScript 进行高级使用
标题为“使用 JavaScript 进行高级使用”import { WebviewVersionChecker } from '@capgo/capacitor-webview-version-checker';
await WebviewVersionChecker.addListener('webViewOutdated', (status) => { console.log('Outdated WebView detected', status);});
await WebviewVersionChecker.check({ minimumMajorVersion: 124, showPromptOnOutdated: true,});为什么要使用这个插件而不是仅仅使用 Capacitor 配置
标题为“为什么要使用这个插件而不是仅仅使用 Capacitor 配置”Capacitor 支持静态最小检查:
android: { minWebViewVersion: 124,},server: { errorPath: 'unsupported-webview.html',}这个插件添加了运行时事件和原生提示 UX,所以用户仍然可以打开并使用应用程序,同时被鼓励更新。
评估顺序:
- 设备共享阈值模式(+数据集),如果提供
minimumDeviceSharePercentDevice-share threshold mode ( - 最新版本模式(
latestVersion/latestVersionApiUrl) - 最小主版本回退(
minimumMajorVersion)
Android 提供商处理
标题:Android 提供商处理该插件支持 Capacitor 在 Android 上使用的两种 WebView 提供商模型:
- Android 5-6 和 10+: Android System WebView (
com.google.android.webview) - Android 7-9:Google Chrome (
com.android.chrome)
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 Getting Started 规划原生媒体和界面行为,连接它 使用@capgo/capacitor-webview-version-checker 为native能力在使用@capgo/capacitor-webview-version-checker 使用@capgo/capacitor-live-activities 为native能力在使用@capgo/capacitor-live-activities @capgo/capacitor-live-activities 为@capgo/capacitor-live-activities实现细节 使用@capgo/capacitor-video-player 为native能力在使用@capgo/capacitor-video-player, 和 @capgo/capacitor-video-player 为@capgo/capacitor-video-player实现细节