@el173/react-native-passcode-auth

中文文档
1.0.1发布于 2020/05/04ISCCommonJS零依赖近 30 天下载 2145

React Native authentication with iOS Passcode.

原始使用文档
文档目录10 节
  1. Install
  2. Usage
  3. Linking the Library (via Cocoa Pods)
  4. Requesting Passcode Authentication
  5. Example
  6. Methods
  7. authenticate(reason)
  8. isSupported()
  9. Errors
  10. License

Forked from react-native-passcode-auth

Changes not in Original Repo

  • Added podspec for iOS

React Native Passcode Auth

React Native Passcode Auth is a React Native library for authenticating users with iOS Passcode. It is an excellent fallback for when Touch ID is not available.

react-native-passcode-auth

Install

React Native Passcode Auth requires iOS 9.0 or later.

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

Usage

Linking the Library (via Cocoa Pods)

Add the following line to your build targets in your Podfile

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

Then run pod install

Requesting Passcode Authentication

Once you've linked the library, you'll want to make it available to your app by requiring it:

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

Requesting Passcode authentication is as simple as calling:

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

Example

Using PasscodeAuth in your app will usually look like this:

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>
    );
  }
});

Methods

authenticate(reason)

Attempts to authenticate with Passcode. Returns a Promise object.

Arguments

  • reason - An optional String that provides a clear reason for requesting authentication.

Examples

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);
  });

isSupported()

Verify's that Passcode Auth is supported and that Passcode is set. Returns a Promise object.

Examples

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

Errors

There are various reasons why authenticating with Passcode may fail. Whenever calling Passcode authentication fails, PasscodeAuth.authenticate will return an error code representing the reason.

Below is a list of error codes that can be returned:

CodeDescription
LAErrorAuthenticationFailedAuthentication was not successful because the user failed to provide valid credentials.
LAErrorUserCancelAuthentication was canceled by the user—for example, the user tapped Cancel in the dialog.
LAErrorUserFallbackAuthentication was canceled because the user tapped the fallback button (Enter Password).
LAErrorSystemCancelAuthentication was canceled by system—for example, if another application came to foreground while the authentication dialog was up.
LAErrorPasscodeNotSetAuthentication could not start because the passcode is not set on the device.
PasscodeAuthNotSetAuthentication could not start because the passcode is not set on the device.
PasscodeAuthNotSupportedDevice does not support Passcode Auth.

More information on errors can be found in Apple's Documentation.

License

Copyright (c) 2015, Naoufal Kadhom

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

版本与发布记录

@el173/react-native-passcode-auth 共发布 2 个版本,首次发布于 2020/05/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2020/05/046 年前
1.0.02020/05/046 年前

关于 @el173/react-native-passcode-auth 的常见问题

@el173/react-native-passcode-auth 是什么?

React Native authentication with 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 和提交记录判断。