react-native - 如何在 React Native 中从 NFC 卡读取数据?
问题描述
所以我在我的项目中使用 react-native-nfc-manager 需要扫描来自 nfc 卡的数据,但它只是在扫描时一直崩溃。它正在正确扫描另一部手机的数据,但在扫描卡时不断崩溃。
我用过 react-native-nfc-manager 包 https://github.com/whitedogg13/react-native-nfc-manager
import React, { Component } from "react";
import { ScrollView, Alert, View, Text, StyleSheet } from "react-native";
import QRCode from "react-native-qrcode";
import { Button } from "native-base";
import { startNFC } from "./NFCHelper";
export default class POS_2MENU extends Component {
static navigationOptions = ({ navigation }) => ({ header: null });
constructor(props) {
super(props);
const { navigation } = this.props;
this.state = { tagValue: null, showProgress: false };
global.payer = navigation.getParam("wallet");
global.amount = navigation.getParam("amount");
global.token = navigation.getParam("token");
global.card = navigation.getParam("card");
}
componentWillMount() {
startNFC(this.handleNFCTagReading);
}
componentWillUnmount() {
// stopNFC();
}
handleNFCTagReading = nfcResult => {
if (nfcResult.Error) {
this.setState({ tagValue: nfcResult.Error.Message });
} else {
alert("nfc data show here");
}
};
render() {
return (
<ScrollView style={styles.homeView}>
{this.state.tagValue ? (
<Text style={styles.tagValue}>{this.state.tagValue}</Text>
) : null}
<View style={styles.container}>
<Button
style={styles.image1}
activeOpacity={0.5}
>
<Text style={{ color: "#fff", fontSize: 20, marginLeft: "18%" }}>
Tap Card Here
</Text>
</Button>
<QRCode
value={global.payer + "," + global.amount}
size={200}
bgColor="#000"
fgColor="#fff"
/>
</View>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
homeView: {
marginTop: 20,
marginBottom: 40
},
container: {
marginTop: 40,
marginLeft: "25%"
},
image1: {
backgroundColor: "#008CBA",
width: 200,
height: 200,
marginBottom: 40
},
tagValue: {
fontWeight: "bold",
fontSize: 16,
marginTop: 40,
paddingLeft: 40,
paddingRight: 40,
textAlign: "center"
}
});
解决方案
推荐阅读
- c# - 如果下一行相同,如何仅删除 1 行
- scala - 使用 spark 版本 2 在 HIVE 中哪个更有效,最大或按 desc 限制 1 排序
- python - 按 Pandas 数据框分组并获取计数
- autosar - Autosar 中的 S/R 和 C/S 调用
- algorithm - 如何确保 LUA 代码中的表中没有重复的相邻值?
- azure - App Service 和 Application Insights 之间的安全连接
- postgresql - Java PostgreSQL:连接失败时抑制错误输出
- c# - 错误:\Bin\Newtonsoft.Json.Net20.dll 和 \Bin\Newtonsoft.Json.dll 中都存在“Newtonsoft.Json.Linq.JObject”类型
- jquery - 如何根据其值隐藏下拉菜单中的选择选项 - wordpress
- r - 如何安排从 postgres 数据库读取数据、进行一些分析并将结果数据写入数据库的 r 脚本的运行?