In that case this is not something that Expo can help you with.
Expo is only returning what the barcode represents. Expo is not adding the ]C1
. It is actually part of the barcode data.
If you find a generic Code 128 barcode generator and generate a barcode for:
12231209
and scan it, you will get the string: "12231209"
. If you parse that with bark-js
, you will get:
{
"symbology": "unknown",
"elements": [
{
"ai": "12",
"title": "DUE DATE",
"value": "2023-12-09",
"raw": "231209"
}
],
"originalBarcode": "12231209"
}
But if you generate a barcode for ]C112231209
, and scan it, you will get the string: "]C112231209"
. If you parse that with bark-js
, you will get:
{
"symbology": "GS1-128",
"elements": [
{
"ai": "12",
"title": "DUE DATE",
"value": "2023-12-09",
"raw": "231209"
}
],
"originalBarcode": "]C112231209"
}
If your users can send any data in a barcode, then how will you know if it’s a GS1 barcode or not? If you know it’s a GS1 barcode, you can parse it with bark-js
. If it starts with ]C1
, then that is a valid GS1-128
barcode that specifies the symbology. If it does not start with ]C1
, it is still valid, but it does not specify the symbology.
If you do not know whether the user intended to scan a GS1 barcode, then you have to guess, or ask the user what type of barcode it is.
If your users sometimes scan barcodes that happen to start with ]C1
and also happen to be parseable as GS1 data, but are not actually GS1 data, then there’s no way to automatically know what it is.
So basically, it seems that the problem is that on iOS, the native barcode scanning code is removing the ]C1
at the start of the data while on Android it is not. If you know the barcode is a GS1 barcode, then this should not matter. If you don’t know what type of barcode it is, you’ll have to decide what to do in that case.
I hope that helps.