Null characters are breaking the data when using barcode scanner on iOS

#1

Hi

I am using the barcode scanner component to scan pdf417 codes on iOS and Android devices. I am testing it on iphone 7 and Motorola g5s plus with 7.1.1 android version.

When scanning on android it works as expected giving me the whole data I need.
I actually can get information that is between the null characters (\u0000)

But when scanning on ios the data is not complete
¿Are maybe the null characters (\u0000) which are breaking the data on ios?

Here is my package.json

{
  "name": "tronex-mobility",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-eslint": "^8.2.3",
    "eslint": "^4.19.1",
    "eslint-config-prettier": "^2.9.0",
    "eslint-config-standard": "^11.0.0",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-node": "^6.0.1",
    "eslint-plugin-prettier": "^2.6.0",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-react": "^7.9.0",
    "eslint-plugin-standard": "^3.1.0",
    "husky": "^0.14.3",
    "jest-expo": "^28.0.0",
    "lint-staged": "^7.1.3",
    "prettier": "^1.13.4",
    "react-native-scripts": "1.14.0",
    "react-test-renderer": "16.3.1"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "lint-staged": {
    "src/**/*.{js,jsx,json}": [
      "prettier --single-quote --trailing-comma all --jsx-bracket-same-line --write",
      "git add"
    ]
  },
  "scripts": {
    "precommit": "lint-staged",
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^6.3.1",
    "axios": "^0.18.0",
    "color": "1.0.3",
    "expo": "^28.0.0",
    "native-base": "^2.4.5",
    "react": "16.3.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-28.0.0.tar.gz",
    "react-navigation": "~2.3.1",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0"
  }
}

And here is my code

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { BarCodeScanner, Permissions } from 'expo';

export default class BarcodeScannerExample extends React.Component {
  state = {
    hasCameraPermission: null,
  }

  async componentWillMount() {
    const { status } = await Permissions.askAsync(Permissions.CAMERA);
    this.setState({hasCameraPermission: status === 'granted'});
    }

  render() {
    const { hasCameraPermission } = this.state;

    if (hasCameraPermission === null) {
      return <Text>Requesting for camera permission</Text>;
    } else if (hasCameraPermission === false) {
      return <Text>No access to camera</Text>;
    } else {
      return (
        <View style={{ flex: 1 }}>
          <BarCodeScanner
            onBarCodeRead={this._handleBarCodeRead}
            style={StyleSheet.absoluteFill}
          />
        </View>
      );
    }
  }

  _handleBarCodeRead = (data) => {
    alert(JSON.stringify(data));
  }
}

I hope anyone could help me

Thanks

#2

This may be an underlying platform issue: https://stackoverflow.com/questions/43888004/reading-qr-code-with-null-byte-in-swift

Maybe you could base64 encode the initial data and display that in the QR code?

#3

I cannot modify de initial data because I am scanning national identity cards

closed #4

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.