跳过内容

Getting Started

GitHub
终端窗口
npm install @capgo/capacitor-persistent-uuid
npx cap sync
import { PersistentUuid } from '@capgo/capacitor-persistent-uuid';
import { 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 标识符。如果 debug 和生产构建使用不同的包标识符但应该共享一个 UUID,请传递一个共享范围。

const result = await PersistentUuid.getId({
scope: 'com.example.app',
});

当用户注销登录、请求隐私重置或自动化测试需要新标识符时,请调用 resetId。

const replacement = await PersistentUuid.resetId();
console.log(replacement.id);
  • 当包名或自定义范围稳定时,Android 可以在卸载和重新安装(包括 Android Studio 和 Play 安装)时存活下来,包括使用不同的签名密钥。
  • 当 Keychain 访问规则保持不变时,iOS 可以在应用更新和 iOS 更新中存活下来。
  • Web 使用 localStorage,并且仅作为开发fallback。

继续从 Getting Started

继续从 Getting Started

如果您正在使用 Getting Started 添加持久性应用标识时,将其与 @capgo/capacitor-persistent-uuid 概述 Android 行为 重新安装行为 iOS 行为 Keychain 行为 使用 @capgo/capacitor-persistent-uuid 教程 Capgo 插件目录 用于其他本机插件。