# @el173/react-native-passcode-auth 中文文档

规范地址：https://npmcn.com/package/%40el173/react-native-passcode-auth/

版本：1\.0\.1
npm 元数据更新时间：2022-04-05T07:03:21.534Z
中文译文更新时间：2026-11-14T07:14:07.053Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40el173/react-native-passcode-auth
原文对照：https://npmcn.com/package/%40el173/react-native-passcode-auth/?lang=original
项目主页：https://github.com/el173/react-native-passcode-auth
源码仓库：https://github.com/el173/react-native-passcode-auth

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：19.5 kB，8 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2020-05-04T08:50:44.553Z
- 最新版本发布：2020-05-04T09:35:14.802Z
- 近 30 天下载量：2145（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

用 iOS Passcode 进行本地认证 .

## 安装

```sh
npm install @el173/react-native-passcode-auth
```

也可以使用：`pnpm add @el173/react-native-passcode-auth`、`yarn add @el173/react-native-passcode-auth`、`bun add @el173/react-native-passcode-auth`

## README

从 [反应-内生-密码-自动](https://github.com/naoufal/react-native-passcode-auth)

# 不在原重现中的更改

-   为 iOS 添加了 postspec

# 反应原生密码 Auth

反应原生密码 Auth 是 [原生反应](http://facebook.github.io/react-native/) 用于认证使用iOS Passcode的用户的库。 它是一个优秀的后退 对于何时 [触摸身份证](https://github.com/naoufal/react-native-touch-id) 无法获取.

![react-native-passcode-auth](https://cloud.githubusercontent.com/assets/1627824/12255178/ed7b46e2-b8be-11e5-8552-f7b60959b43c.gif)

## 安装

反应原生密码 Auth **需要 iOS 9.0 或以后**。 。 。 .

```shell
npm i --save @el173/react-native-passcode-auth
```

## 使用量

### 将图书馆连接起来(通过可可站)

在您的构建目标中添加以下行 `Podfile`

`pod 'PasscodeAuth', :path => '../node_modules/@el173/react-native-passcode-auth'`

然后运行 `pod install`

### 请求密码认证

一旦你把图书馆连起来,你就会想通过要求它提供给你的应用程序:

```js
import PasscodeAuth from '@el173/react-native-passcode-auth';
```

请求密码认证和呼叫一样简单:

```js
PasscodeAuth.authenticate('to demo this react-native component')
  .then(success => {
    // Success code
  })
  .catch(error => {
    // Failure code
  });
```

## 示例

在您的应用程序中使用 PasscodeAuth 通常会这样:

```js
import React, { Component, AlertIOS, TouchableHighlight, View, Text } from 'react-native';
import PasscodeAuth form 'react-native-passcode-auth';

class YourComponent extends Component {
  _pressHandler() {
    PasscodeAuth.authenticate('to demo this react-native component')
      .then(success => {
        AlertIOS.alert('Authenticated Successfully');
      })
      .catch(error => {
        AlertIOS.alert('Authentication Failed');
      });
  }

  render() {
    return (
      <View>
        ...
        <TouchableHighlight onPress={this._pressHandler}>
          <Text>
            Authenticate with Passcode
          </Text>
        </TouchableHighlight>
      </View>
    );
  }
});
```

## 方法

### 认证( 理由)

试图用密码认证. 回返a `Promise` 对象.

**参数**

-   `reason` - 一个 _选项_ `String` 这为请求认证提供了明确的理由.

**实例**

```js
PasscodeAuth.authenticate('to demo this react-native component')
  .then(success => {
    // Success code
    console.log('User authenticated with Passcode');
  })
  .catch(error => {
    // Failure code
    console.log(error);
  });
```

### 已支持 ()

验证是否支持密码 Auth 并设定了密码 . 回返a `Promise` 对象.

**实例**

```js
PasscodeAuth.isSupported()
  .then(supported => {
    // Success code
    console.log('Passcode Auth is supported.');
  })
  .catch(error => {
    // Failure code
    console.log(error);
  });
```

## 错误

使用 Passcode 认证可能失败的原因多种多样. 当呼叫密码认证失败时, `PasscodeAuth.authenticate` 将返回代表原因的错误代码.

以下是可以返回的错误代码列表 :

| 代码 | 说明 |
| --- | --- |
| `LAErrorAuthenticationFailed` | 由于用户未能提供有效证书,认证未能成功. |
| `LAErrorUserCancel` | 用户取消了认证 - 例如, 用户在对话框中点击了 Cancel . |
| `LAErrorUserFallback` | 认证被取消, 因为用户已按下后退按钮( Enter Phone) . |
| `LAErrorSystemCancel` | 系统取消了认证—— 例如, 如果认证对话框启动时有另一个应用程序出现。 Name. |
| `LAErrorPasscodeNotSet` | 无法启动认证, 因为密码没有设置在设备上 . |
| `PasscodeAuthNotSet` | 无法启动认证, 因为密码没有设置在设备上 . |
| `PasscodeAuthNotSupported` | 设备不支持 Passcode Auth . |

_关于错误的更多信息,请访问 [苹果的文档](https://developer.apple.com/library/prerelease/ios/documentation/LocalAuthentication/Reference/LAContext_Class/index.html#//apple_ref/c/tdef/LAError)。 。 。 ._

## 许可证

版权(c)2015年, [纳乌法尔·卡德洪姆](http://naoufal.com/)

特此准许为任何目的使用、复制、修改和(或)分发这种软件,不论是否收费,但上述版权通知和这项许可通知须以所有副本印发.

软件被提供"AS IS", 并且授权 发布所有关于这个软件的警告, 包括所有包含的 危险和可识别性。 任何特别的、直接的、间接的、或因果的、或因使用、数据或方案的损失而产生的任何特别的、直接的、间接的、或因果的、或因果的、或因使用、数据或方案而造成的任何损失,或因使用或执行本软件而产生的任何特别的、直接的、间接的、间接的、或因果的、间接的、或因果的、或因使用、数据或方案而造成的任何特别、直接的、间接的、或因果的、间接的或因果的、或因果的、或因果的、或因果的、或因使用或执行本软件而产生的任何特别的、直接的、间接的、间接的或因果的或因果的或因果的、数据或因果的、数据或因果的、数据或因果的、数据或因果的、数据或因果的、数据或因果的、或因果的、或因果的、或因果的、或因果的、或因果的、或因果的、或因的、或因果的、或因果的、或因果的、或因果的.

## 常见问题

### @el173/react-native-passcode-auth 是什么？

用 iOS Passcode 进行本地认证 \.

### 如何安装 @el173/react-native-passcode-auth？

在项目目录运行 npm install @el173/react-native-passcode-auth，或使用 pnpm add / yarn add / bun add。

### @el173/react-native-passcode-auth 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/el173\_\_react-native-passcode-auth 是否存在。

### @el173/react-native-passcode-auth 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @el173/react-native-passcode-auth 可以商用吗？

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

### @el173/react-native-passcode-auth 的下载量有多少？

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

### @el173/react-native-passcode-auth 还在维护吗？

最新版本 1\.0\.1 发布于 2020/05/04（6 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/05/04。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

