在本机反应中使用设备 ID 生成 Qr [英] Generate Qr using device id in react native

查看:72
本文介绍了在本机反应中使用设备 ID 生成 Qr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户设备 ID 生成 Qr 代码,但输出为空白,可能是什么错误?

I'm trying to Generate Qr code based on user device id buut i'm getting blank output what could be the error ?

import React from "react";

import { StyleSheet, View } from "react-native";
import DeviceInfo from "react-native-device-info";
import QRCode from "react-native-qrcode-svg";
import Button from "../components/Button";

function QrGenerator() {
  let deviceId = DeviceInfo.getDeviceId();
  console.log(deviceId);
  return (
    <View style={styles.MainContainer}>
      <QRCode
        value={"999" + deviceId}
        size={250}
        bgColor="#000"
        fgColor="#fff"
      />

      <Button
        title="Back"
        style={styles.Tbutton}
        onPress={() => {
          this.props.navigation.navigate("splash");
        }}
      />
    </View>
  );
}
export default QrGenerator;

const styles = StyleSheet.create({
  MainContainer: {
    flex: 1,
    margin: 10,
    alignItems: "center",
    paddingTop: 200,
  },
  Tbutton: {
    marginTop: 30,
    marginBottom: 8,
    padding: 13,
    borderRadius: 10,
  },
});

我的程序中还有一个错误是Invariant Violation: Native module cannot be null.我绑定了删除节点模块并重新安装但得到同样的错误.

also another in my program there is error that is Invariant Violation: Native module cannot be null. i tied to delete node module and re install but getting same error.

推荐答案

您可以使用 rn-qr-generator 模块使用给定的字符串创建二维码图像.要生成带有对象的 QRCode 图像,只需执行以下操作

You can use rn-qr-generator module to create QRCode Image with a given string. To generate a QRCode image with an object just do something like this

import RNQRGenerator from 'rn-qr-generator';
 
RNQRGenerator.generate({
  value: deviceId,
  height: 100,
  width: 100,
  base64: false,            // default 'false'
  backgroundColor: 'black', // default 'white'
  color: 'white',           // default 'black'
})
  .then(response => {
    const { uri, width, height, base64 } = response;
    this.setState({ imageUri: uri });
  })
  .catch(error => console.log('Cannot create QR code', error));

这篇关于在本机反应中使用设备 ID 生成 Qr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆