@didomi/react-native

中文文档
2.39.0发布于 2026/11/10BSD-3TypeScriptESM + CJS构建来源已验证近 30 天下载 6.3万

Didomi React Native SDK

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Configuration with local file
  4. Documentation
  5. Example applications
  6. Suggesting improvements
  7. License

Didomi React Native

Didomi is a leading Consent Management Platform that allows companies to collect, store, and leverage user consent under GDPR, CCPA, and other data privacy regulations. This plugin enables React Native developers to get in compliance and optimize their consent rate and monetization on native mobile apps.

This repository contains the source code and a sample app for the Didomi React Native plugin. This plugin enables React Native developers to easily use Didomi's Consent Management Platform on Android and iOS apps.

Installation

Install using yarn add @didomi/react-native Or npm i @didomi/react-native

Then install required pods for iOS with cd ios && pod install

As Didomi requires Swift runtime for iOS, you may need to add an empty Swift file (to create a briding header) into Xcode project.

Usage

import { Didomi, DidomiEventType } from '@didomi/react-native';
import { useEffect } from 'react';

// ...
function App() {
  useEffect(() => {
    // Initialize and setup UI
    // The initialize function need to be called only once and as early as possible to give time for the SDK initialization
    Didomi.initialize('YOUR_API_KEY', undefined, undefined, undefined, false, undefined, 'YOUR_NOTICE_ID');

    // The setupUI displays the popup and is only available once the SDK sent the onReady events
    Didomi.setupUI();
  }, [])
  return (
    <SafeAreaView style={{ flex: 1 }}>
      // ...
    </SafeAreaView>
  );
}

//...

// Retrieve data
const purposes = await Didomi.getEnabledPurposes();
const status = await Didomi.getUserStatusForVendor('vendorId');

//...

// Register an event listener
Didomi.addEventListener(DidomiEventType.SHOW_NOTICE, () => {
  console.log('Show notice');
});

//...

For a complete overview of available methods and events, have a look at the online documentation.

Configuration with local file

In case you need to use a local configuration. The didomi_config.json must be added to native iOS and Android projects.

On iOS, drag and drop the file to Xcode files.

On Android, copy it to the src/main/assets folder.

Documentation

For complete instructions on installing and using the plugin, please read our documentation:

Developer guide

API reference

Example applications

Sources contain 2 applications: /test (an app designed mostly for UI testing ) and /sample (more human friendly app).

They can be run with:

# test or sample Application
cd sample
cd ios && pod install
cd ..
npx react-native run-ios
# or npx react-native run-android

Suggesting improvements

To file bugs, make feature requests, or to suggest other improvements, please use Github's issue tracker.

License

Modified BSD License (BSD-3)

版本与发布记录

@didomi/react-native 共发布 75 个版本,首次发布于 2021/06/25;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.39.0latest2026/11/101 天前
2.38.12026/10/2913 天前
2.38.02026/10/2616 天前
2.37.12026/10/2121 天前
2.37.02026/10/1230 天前
2.36.02026/09/281 个月前

关于 @didomi/react-native 的常见问题

@didomi/react-native 是什么?

Didomi React Native SDK

如何安装 @didomi/react-native?

在项目目录运行 npm install @didomi/react-native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(>=0.77.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@didomi/react-native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@didomi/react-native 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@didomi/react-native 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@didomi/react-native 可以商用吗?

@didomi/react-native 使用 BSD-3 许可。声明的许可为 BSD-3,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@didomi/react-native 的下载量有多少?

根据 npm 官方下载统计,@didomi/react-native 在 2026/10/12 – 2026/11/10 这 30 天内被下载 62,698 次,日均约 2,090 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@didomi/react-native 还在维护吗?

最新版本 2.39.0 发布于 2026/11/10(1 天前);至今共发布 75 个版本,其中过去 12 个月发布了 26 个;首次发布于 2021/06/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。