【发布时间】:2023-02-12 04:05:59
【问题描述】:
我正在使用 expo 条码扫描仪扫描一些条码,当我扫描时返回的数据值每次都不同。我认为条形码应该有一个不会改变的唯一编号,或者我错了吗?这是我的实现
const handleBarCodeScanned = ({ type, data }) => {
try {
console.log(type); //this returns 1024
console.log(data); //this value is different every time
setData(data);
setScanned(true);
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
} catch (error) {
alert(`we did not recognize the barcode.Please try again`);
console.error("Unable to parse string: ", error);
}
};
<BarCodeScanner
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
barCodeTypes={[BarCodeScanner.Constants.BarCodeType.code93]}
style={[StyleSheet.absoluteFillObject, styles.minicontainer]}
/>
{scanned && <Button title={"Tap to Scan Again"} onPress={Rescan} />}
</View>
在 console.log(data) 上返回一个不同的值应该是这样的吗?还是某处有问题。
ps:我没有收到它发送给我的条形码,我正在通过我的电脑屏幕扫描它们。可以确定吗?
【问题讨论】:
标签: react-native expo barcode barcode-scanner