指南
Persistent UUID 的教程
使用 @capgo/capacitor-persistent-uuid
为 Capacitor 生成一个持久的应用范围 UUID,并在正常应用存储被删除的重新安装和更新流程中保持稳定。
安装
npm install @capgo/capacitor-persistent-uuid
npx cap sync
此插件暴露的内容
- getId - 读取存储的 UUID,创建一个如果不存在的 UUID 的选定范围。
- resetId - 重新生成存储的 UUID 以支持注销、隐私重置或测试清理流程。
- scope - 可选的命名空间,用于应用程序的 debug 和生产包标识符不同。
示例用法
import { PersistentUuid } from '@capgo/capacitor-persistent-uuid';
const { id, created, scope } = await PersistentUuid.getId();
console.log(id);
console.log(created);
console.log(scope);
共享 UUID Across Build Variants
const result = await PersistentUuid.getId({
scope: 'com.example.app',
});
console.log(result.id);
重置标识符
const replacement = await PersistentUuid.resetId();
console.log(replacement.id);
平台说明
Android 将 UUID 存储在 AccountManager 中,使其可以在 Android Studio reinstall 周期和 debug vs Play 签名差异时生存,当包名或自定义范围稳定时。 iOS 将 UUID 存储在 Keychain 中,并在 Keychain 访问保持兼容的情况下保持不变。 Web 使用 localStorage 作为开发fallback。
此插件不暴露硬件 ID,并且不支持工厂重置、手动帐户删除、Keychain 清除、浏览器存储清除或 resetId。
完整参考
- GitHub: https://github.com/Cap-go/capacitor-persistent-uuid/
- 文档: /docs/plugins/persistent-uuid/
继续
如果您正在使用 @capgo/capacitor-persistent-uuid 以保持应用程序身份稳定,连接它与 @capgo/capacitor-persistent-uuid 概述 开始 安装和API示例 安卓行为 重新安装详细信息 iOS行为 钥匙串详细信息 @capgo/capacitor-persistent-account 当您需要账户数据持久化而不是UUID时。