跳过内容

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';
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安装时使用不同的签名密钥。
  • iOS在Keychain访问规则保持不变的情况下,能够在应用更新和iOS更新中存活。
  • Web使用localStorage,并且仅作为开发fallback。

从Getting Started继续

标题:从Getting Started继续

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