Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 703 forks source link

Problem with ZXing (Xamarin cross-platform) #490

Closed alexgg94 closed 4 years ago

alexgg94 commented 7 years ago

Hi everyone,

I have a Xamarin solution with Android, iOS and UWP projects. I am trying to use ZXing in order to read some barcodes but i found some problems.

This is the way I use it:

try
{
  this.scanner = new ZXing.Mobile.MobileBarcodeScanner();
  this.result = await scanner.Scan();
  this.text = this.result.Text;
}

catch (Exception ex)
{
  this.text = "No code";
}

This is what i've done for each platform:

Android:

  1. Install ZXing.Net.Mobile version 2.1.47 and Zxing.Net.Mobile.Forms version 2.1.47 packages.
  2. Edit AndroidManifest.xml by adding permissions for camera and flashlight:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
  1. Edit MainActivity.cs by adding the following lines:
protected override void OnCreate(Bundle bundle)
{
 .
 .
 .
  MobileBarcodeScanner.Initialize(Application);
 .
 .
 .
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
 global::ZXing.Net.Mobile.Forms.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

This works fine but, at some random? scanning, the screen gets black before the scanning starts, the application doesn't work any more and it has to be manually killed. As I kill the application manually, I don't have access to the camera any more until I reboot the device (I think that's because the camera it is never released by the application instance killed manually).

iOS:

  1. Install ZXing.Net.Mobile version 2.1.47 and Zxing.Net.Mobile.Forms version 2.1.47 packages.

App ends before the scanning starts and I get:

Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.

UWP:

  1. Install ZXing.Net.Mobile version 2.1.47 and Zxing.Net.Mobile.Forms version 2.1.47 packages.
  2. Add to Package.appxmanifest Capabilities Microphone (doesn't make sense but i've read in some places that it has to be enabled) and Webcam.

App ends just after the scanning and I get:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Extra info: Xamarin.Forms version 2.3.2.127

Am I missing something?

Thanks

stepheaw commented 7 years ago

I'm having the same issue on iOS. I have not tested on any other platforms. Is there any update on this?

dramosti commented 7 years ago

I Have the same problem !! Is there any solution ?? pleaseeee!!!

AntonChekalin commented 7 years ago

Hi! I have the same issue, but only on iOs versions 10+ On 8.4.1 it works like a charm

UPD: I found solution here: https://forums.xamarin.com/discussion/77721/zxingscannerview-does-not-work-anymore-in-ios-10

em19 commented 7 years ago

I had a similar issue on Android. Although the app was never killed before the scanner page was closed the camera wasn't released properly at some point. Therefore after another start of the app the camera service couldn't be accessed.

jamilattar commented 7 years ago

Have you tried "ZXing.Net.Mobile for Forms"? It's easer.

Folow the instructions in this link: https://components.xamarin.com/gettingstarted/zxing.net.mobile.forms

Redth commented 4 years ago

Thanks for reporting this issue! Unforunately it took me way too long to respond 😭. Sorry, I apologize! Recently the source code for this project was completely refactored to modernize it. Many PR's were included in this effort, and many bugs were hopefully fixed. Please try out the latest 3.x series of NuGet packages (currently in prerelease). To try and make the project more maintainable in my spare time going forward, I've decided to close all existing issues to start with a clean slate. If you're still experiencing this issue on the newest version, please open a new issue with as much detail as possible. Thank you for your patience and understanding! Happy scanning!