跳过内容

Getting Started

GitHub

您可以使用我们的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-uuid
npx cap sync
import { PersistentUuid } from '@capgo/capacitor-persistent-uuid';

读取或创建 UUID

读取或创建 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,相同的作用域下。

使用稳定的自定义作用域

标题:使用稳定的自定义作用域

原生默认作用域是安卓的包名和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安装,包名或自定义范围保持稳定。
  • iOS在Keychain访问规则保持不变的情况下可以在应用更新和iOS更新时生存。
  • Web使用localStorage并且仅作为开发fallback。

如果您正在使用 Getting Started 来添加持久的应用身份,请将其连接到 @capgo/capacitor-persistent-uuid 概述 Android行为 重新安装行为 iOS行为 对于Keychain行为, 使用@capgo/capacitor-persistent-uuid 为教程 Capgo插件目录 其他本机插件