@castleio/react-native-castle

中文文档
4.1.0发布于 2026/10/12MITTypeScriptESM + CJS近 30 天下载 2.3万

Castle SDK for React Native

原始使用文档
文档目录12 节
  1. Requirements
  2. React Native
  3. iOS
  4. Android
  5. Installation
  6. yarn
  7. npm
  8. Linking Native Code on iOS
  9. Liking Native Code on Android
  10. Usage
  11. Contributing
  12. License

Castle for React Native

Castle adds real-time monitoring to your authentication stack, instantly notifying you and your users of potential account hijacks.

npm License CircleCI

NOTE: Version 4.0.0 has breaking changes compared to previous 2.x.x versions. Android now requires 8.0+ (minSdkVersion 26, compileSdkVersion 36), so apps supporting API 24-25 cannot upgrade, and the iOS deployment target was raised from 12.0 to 13.0. In addition:

  • userAgent(), queueSize() and the sensorTrackingEnabled option have been removed.
  • flushIfNeeded() and baseUrl() are iOS only. On Android flushIfNeeded() is a no-op and baseUrl() resolves null.
  • createRequestToken() resolves null instead of an empty string before the SDK has been configured.
  • configure() and configureWithPublishableKey() reject the promise when configuration fails instead of resolving.
  • baseURLAllowList entries must include a scheme, for example https://api.example.com.

See the CHANGELOG for the full list.

Requirements

React Native

  • React Native 0.77.0+

iOS

  • iOS 15.1+
  • Xcode 16.3+

Android

  • Android 8.0 (API 26)
  • compileSdkVersion 36

Installation

Add the @castleio/react-native-castle package to your package.json.

yarn

yarn add @castleio/react-native-castle

npm

npm install --save @castleio/react-native-castle

Linking Native Code on iOS

Run pod install in the ios directory in order to link to the native iOS project. A shortcut for doing this without switching directories is to run

npx pod-install

The Castle iOS SDK ships as a binary XCFramework vendored inside this package, so CocoaPods links, embeds and signs it for you. No extra Podfile setup is required.

Once completed, re-build the app binary and start using the library

npx react-native run-ios

Liking Native Code on Android

In order to start using the library you'll need to re-build the app binary

npx react-native run-android

Usage

Please see the Mobile Integration Guide.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

版本与发布记录

@castleio/react-native-castle 共发布 46 个版本,首次发布于 2021/03/11;过去 12 个月发布了 9 个版本。

版本发布日期距今
4.1.0latest2026/10/1227 天前
4.0.12026/09/161 个月前
4.0.02026/08/262 个月前
2.3.02026/05/285 个月前
2.0.15legacy2026/04/176 个月前
2.2.82026/01/279 个月前

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

@castleio/react-native-castle 是什么?

Castle SDK for React Native

如何安装 @castleio/react-native-castle?

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

@castleio/react-native-castle 支持 TypeScript 吗?

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

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

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

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

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

@castleio/react-native-castle 可以商用吗?

@castleio/react-native-castle 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

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

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

@castleio/react-native-castle 还在维护吗?

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