开始使用
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-persistent-uuid`
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/persistent-uuid/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-persistent-uuid` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
npm install @capgo/capacitor-persistent-uuidnpx cap sync导入
标题:导入import { PersistentUuid } from '@capgo/capacitor-persistent-uuid';读取或创建 UUID
标题:读取或创建 UUIDimport { PersistentUuid } from '@capgo/capacitor-persistent-uuid';
const result = await PersistentUuid.getId();
console.log(result.id);console.log(result.scope);console.log(result.created);第一次调用创建并存储 UUID。后续调用返回相同的 UUID,相同的范围内。
使用稳定的自定义范围
标题:使用稳定的自定义范围原生默认范围是 Android 的包名和 iOS 的 bundle identifier。如果 debug 和 production 构建使用不同的包标识符但应该共享一个 UUID,请传递一个共享范围。
const result = await PersistentUuid.getId({ scope: 'com.example.app',});重置 UUID
标题:重置 UUID当用户注销登录、请求隐私重置或自动化测试需要新标识符时,请调用 resetId。
const replacement = await PersistentUuid.resetId();console.log(replacement.id);持久性期望
标题:持久性期望- 当包名或自定义范围稳定时,Android 可以在卸载和重新安装(包括 Android Studio 和 Play 安装)以及使用不同签名密钥的 Android Studio 和 Play 安装时生存。
- iOS 在 Keychain 访问规则保持不变的情况下可以在应用更新和 iOS 更新中生存。
- Web 使用 localStorage,并且仅作为开发fallback
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 开始使用 为应用添加持久身份,连接它 @capgo/capacitor-persistent-uuid 概览 Android行为 重新安装行为 iOS行为 Keychain行为 使用@capgo/capacitor-persistent-uuid 教程 Capgo插件目录 其他本机插件