0

我目前正在尝试使用 React Native 构建一个应用程序,用户可以在其中输入数据,生成二维码,然后共享相同的二维码。

输入数据并生成 QR 码按预期工作。然而,分享是让我挣扎的原因。目前我将数据保存为普通变量,并使用“react-native-qrcode-svg”显示二维码。对于共享部分,我使用“react-native-share”。

后者给了我这个错误:

TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNShare.FACEBOOK')

我的代码:

export default function App() {
  return (
    <View style={styles.container}>
       <QRCode
          value={JSON.stringify({test: 'testdata'})}
          getRef={c => (this.svg = c)}
        />
        <TouchableOpacity onPress={this.saveQRCode}>
          <View style={styles.instructions}>
            <Text>Share QR code</Text>
          </View>
        </TouchableOpacity>
    </View>
  );
}

saveQRCode = () => {
  this.svg.toDataURL(this.callback);
};


callback = (dataURL) => {
  console.log(dataURL);
  let shareImageBase64 = {
    title: 'React Native',
    url: `data:image/png;base64,${dataURL}`,
    subject: 'Share Link', //  for email
  };
  Share.open(shareImageBase64).catch(error => console.log(error));
}

任何帮助是极大的赞赏。

4

1 回答 1

0

我有一个已被弹出的世博会项目,我通过停止 metro ,运行npx pod-install,然后在启动所有内容之前从模拟器中卸载应用程序来解决这个问题。

另请参考这些问题以获得帮助:

https://github.com/react-native-share/react-native-share/issues/322

https://github.com/react-native-share/react-native-share/issues/837

于 2021-12-07T17:51:51.590 回答