React native touch id无效

时间:2017-10-26 09:01:13

标签: android ios react-native touch-id

我想在react native中创建touch id本地身份验证。我用了

npm react-native-touch-id

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  TouchableHighlight
} from 'react-native';

var LocalAuth = require('react-native-touch-id')

var YourComponent = React.createClass({
  _pressHandler() {
    LocalAuth.authenticate({
        reason: 'this is a secure area, please authenticate yourself',
        falbackToPasscode: true,    // fallback to passcode on cancel
        suppressEnterPassword: true // disallow Enter Password fallback
      })
      .then(success => {
        AlertIOS.alert('Authenticated Successfully')
      })
      .catch(error => {
        AlertIOS.alert('Authentication Failed', error.message)
      })
  },

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

但它没有说什么,我按照这个链接

https://github.com/ElekenAgency/react-native-touch-id-android

1 个答案:

答案 0 :(得分:1)

来到这里是因为我有同样的问题,但是看看你的代码我认为你已经迷失了混合库。

看看这一行:

var LocalAuth = require('react-native-touch-id')

您正在导入LocalAuth,我相信它是react-native-local-auth基于react-native-touch-id构建的react-native-touch-id-android库的一部分,同时遵循第3个库的教程{{1} 1}}。

根据回购中的示例,您的导入应如下所示:

import Finger from 'react-native-touch-id-android'

我猜他之所以没有崩溃,是因为你在尝试react-native-local-auth的过程中已经安装了react-native-touch-id-android

最好从头开始 - 转到package.json并删除上述库,然后运行npm install,然后按照您发布的回购中的分步指南进行操作。< / p>

如果你事后回来并报告它是否成功,我会很高兴。祝你好运。