Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zxing crash on iOS 10 #421

Closed
iMacX opened this issue Sep 14, 2016 · 30 comments
Closed

Zxing crash on iOS 10 #421

iMacX opened this issue Sep 14, 2016 · 30 comments

Comments

@iMacX
Copy link

iMacX commented Sep 14, 2016

Hi,

we are using the latest stable version of Zxing (2.1.47) and it crashes on iOS 10.0.1.

Are you aware of this? Any fix on the road?

Thank you

@MKahmen
Copy link

MKahmen commented Sep 14, 2016

Same for me.

Xamarin Forms 2.3.2.127
ZXing.Net.Mobile(.Forms) 2.1.47

2016-09-14 17:29:59.033 xxxxxxxxxxxxxx.iOS[336:35119] ZXingScannerView.Setup() took 0.128 ms.
2016-09-14 17:29:59.033 xxxxxxxxxxxxxx.iOS[336:35119] StartScanning
2016-09-14 17:29:59.096 xxxxxxxxxxxxxx.iOS[336:35119] PERF: Alloc AVCaptureVideoPreviewLayer took 7.633 ms.
then it crashes...

@iMacX
Copy link
Author

iMacX commented Sep 14, 2016

Ok, I found the solution.

Just add the NSCameraUsageDescription key to info.plist

<key>NSCameraUsageDescription</key>
<string>Can we use your camera</string>

@MKahmen
Copy link

MKahmen commented Sep 14, 2016

Works. Thanks @iMacX

@lokan82
Copy link

lokan82 commented Sep 14, 2016

Unfortunately, that fix doesn't seem to work for iOS apps. I also tried it by creating a new blank single view iOS app but it crash on that as well. With or without the NSCameraUsageDescription in plist.info.

Shortened stacktrace:

critical: at <0xffffffff>
critical: at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (intptr,intptr,intptr) <0x00012>
critical: at AVFoundation.AVCaptureSession.set_SessionPreset (Foundation.NSString) [0x00022] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/build/ios/native/AVFoundation/AVCaptureSession.g.cs:418
critical: at ZXing.Mobile.ZXingScannerView.SetupCaptureSession () <IL 0x000f9, 0x00a0a>
critical: at ZXing.Mobile.ZXingScannerView.b__36_0 () <IL 0x00002, 0x00063>
critical: at Foundation.NSActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/Foundation/NSAction.cs:57
critical: at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x00020, 0x000cc>

@nkallman
Copy link

lokan82, do you think this problem might be related to #422

@superlsp
Copy link

Thanks @iMacX

@kparks29
Copy link

the fix doesnt work for me either

@NicolasDorier
Copy link

This fixed for me, for god sake Xamarin, hire a QA team... I like your product but I can't dev 10min without stuff like that constantly happening :(

@iMacX
Copy link
Author

iMacX commented Sep 29, 2016

@NicolasDorier This bug has nothing to do with xamarin. It's a new requirement in iOS 10 introduced by Apple.

@NicolasDorier
Copy link

@iMacX so maybe at least a nice exception instead of a saddistic segfault error, would save some man-hours.

@lukepothier
Copy link

lukepothier commented Oct 4, 2016

The fix from @iMacX doesn't work for me either.

Xamarin.iOS 10.0.0.1

2016-10-04 13:51:56.208 xxx.ios[32988:932942] Starting to scan...
2016-10-04 13:51:56.229 xxx.ios[32988:932942] ZXingScannerView.Setup() took 13.191 ms.
2016-10-04 13:51:56.229 xxx.ios[32988:932942] StartScanning
2016-10-04 13:51:56.238 xxx.ios[32988:932942] critical: Stacktrace:
2016-10-04 13:51:56.239 xxx.ios[32988:932942] critical:   at <unknown> <0xffffffff>
2016-10-04 13:51:56.239 xxx.ios[32988:932942] critical:   at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (intptr,intptr,intptr) <0x00012>
2016-10-04 13:51:56.240 xxx.ios[32988:932942] critical:   at AVFoundation.AVCaptureSession.set_SessionPreset (Foundation.NSString) [0x0001a] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/build/ios/native/AVFoundation/AVCaptureSession.g.cs:418
2016-10-04 13:51:56.240 xxx.ios[32988:932942] critical:   at ZXing.Mobile.ZXingScannerView.SetupCaptureSession () <IL 0x000f9, 0x00a0e>
2016-10-04 13:51:56.240 xxx.ios[32988:932942] critical:   at ZXing.Mobile.ZXingScannerView.<StartScanning>b__36_0 () <IL 0x00002, 0x00063>
2016-10-04 13:51:56.241 xxx.ios[32988:932942] critical:   at Foundation.NSActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/Foundation/NSAction.cs:57
2016-10-04 13:51:56.241 xxx.ios[32988:932942] critical:   at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x00020, 0x000cc>
2016-10-04 13:51:56.241 xxx.ios[32988:932942] critical:   at <unknown> <0xffffffff>
2016-10-04 13:51:56.242 xxx.ios[32988:932942] critical:   at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_bool (intptr,intptr,intptr,intptr,bool) <0x00012>
2016-10-04 13:51:56.242 xxx.ios[32988:932942] critical:   at Foundation.NSObject.InvokeOnMainThread (System.Action) [0x00007] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/Foundation/NSObject2.cs:560
2016-10-04 13:51:56.243 xxx.ios[32988:932942] critical:   at ZXing.Mobile.ZXingScannerView.StartScanning (System.Action`1<ZXing.Result>,ZXing.Mobile.MobileBarcodeScanningOptions) <IL 0x00060, 0x00297>
2016-10-04 13:51:56.243 xxx.ios[32988:932942] critical:   at ZXing.Mobile.ZXingScannerViewController.<ViewDidAppear>b__33_1 () <IL 0x00018, 0x000e7>
2016-10-04 13:51:56.243 xxx.ios[32988:932942] critical:   at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/Foundation/NSAction.cs:163
2016-10-04 13:51:56.243 xxx.ios[32988:932942] critical:   at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x00020, 0x000cc>
2016-10-04 13:51:56.244 xxx.ios[32988:932942] critical:   at <unknown> <0xffffffff>
2016-10-04 13:51:56.244 xxx.ios[32988:932942] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00012>
2016-10-04 13:51:56.244 xxx.ios[32988:932942] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/UIKit/UIApplication.cs:79
2016-10-04 13:51:56.245 xxx.ios[32988:932942] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/UIKit/UIApplication.cs:63
2016-10-04 13:51:56.245 xxx.ios[32988:932942] critical:   at xxx.ios.ios.Application.Main (string[]) [0x00002] in C:\Path\To\Solution\xxx.ios\Main.cs:15
2016-10-04 13:51:56.245 xxx.ios[32988:932942] critical:   at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00051, 0x001d6>
2016-10-04 13:51:56.246 xxx.ios[32988:932942] critical: 
Native stacktrace:
2016-10-04 13:51:56.246 xxx.ios[32988:932942] critical: 
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

@lokan82
Copy link

lokan82 commented Oct 4, 2016

I found that it works when debugging on a real device, when I use the simulator it dies with the error above.

@lukepothier
Copy link

@lokan82 we're getting the same crash on real devices. Are you seeing it work on real devices with or without the NSCameraUsageDescription key?

@lokan82
Copy link

lokan82 commented Oct 4, 2016

With NSCameraUsageDescription added to info.plist

@lukepothier
Copy link

@iMacX and @lokan82 thanks for the tip, the NSCameraUsageDescription fix worked for me on a real device (but not on the simulator).

@EtienneFK
Copy link

Got exactly the same issue.

Does a fix is on the road?

Regards,
Estema

@reerden
Copy link

reerden commented Oct 10, 2016

Even with NSCameraUsageDescription added to info.plist it's not working for me.

@Redth
Copy link
Owner

Redth commented Oct 10, 2016

@NicolasDorier Apple decided to cause a segfault in iOS 10 if you are missing the info.plist entry, this isn't xamarin's fault. Furthermore this Lib is not officially supported by Xamarin, I just happen to work at Xamarin and work on it in my spare time. So apologies if this free and open source project isn't quite perfect. You are always welcome to submit a PR with any fixes and improvements even if it's just updating the README. Cheers!

@NicolasDorier
Copy link

@Redth sorry, I was not even using ZXing when I encountered this exception. Somehow, I thought I was commenting on the Xamarin project. This problem can't be fixed at ZXing level, it is the fault of Xamarin.

@micropole-cdescours
Copy link

micropole-cdescours commented Oct 12, 2016

On iOS 10, I've made it worked by adding NSCameraUsageDescription in plist and by asking permission for camera usage with this kind of code :

        void BtnScan_TouchUpInside(object sender, EventArgs e)
        {
            switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video))
            {
                case AVAuthorizationStatus.Authorized:
                    // User granted camera access.
                    scan();
                    break;
                case AVAuthorizationStatus.Denied:
                    // User denied camera access.
                    break;
                case AVAuthorizationStatus.Restricted:
                    // Camera access is restricted. Should not happen for AVMediaType.Video.
                    // Check AVCaptureDevice.Devices.Length > 0 to determine if there is a video device
                    // before using this code.
                    break;
                case AVAuthorizationStatus.NotDetermined:
                    // Ask user for camera access.

                    if (AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video).Result)
                    {
                        // User granted camera access.
                        scan();
                    }

                    else
                    {
                        // User denied camera access.
                    }
                    break;

                default:
                    break;
            }


        }

        void scan()
        {
            //Create a new instance of our scanner
            MobileBarcodeScanner scanner;
            scanner = new MobileBarcodeScanner(this);

            Task.Run(async () =>
           {
               //Tell our scanner to use the default overlay
               scanner.UseCustomOverlay = false;
               //We can customize the top and bottom text of the default overlay
               //Start scanning
               var result = await scanner.Scan();

               HandleScanResult(result);
           });
        }

        void HandleScanResult(ZXing.Result result)
        {
            string msg = "";

            if (result != null && !string.IsNullOrEmpty(result.Text))
                msg = "Found Barcode: " + result.Text;
            else
                msg = "Scanning Canceled!";

            this.InvokeOnMainThread(() =>
            {
                var av = new UIAlertView("Barcode Result", msg, null, "OK", null);
                av.Show();
            });
        } 

@jidsi
Copy link

jidsi commented Oct 28, 2016

I could fixed the problem.
Error will occur in the next source.
ZXing.Net.Mobile.iOS.ZXingScannerView.cs
bool SetupCaptureSession ()

my source is below.
http://itblogdsi.blog.fc2.com/blog-entry-71.html

@faceoffers28
Copy link

I haven't encountered this issue because I don't have an iOS 10 device. I was thinking about upgrading my iOS 6S, but I hate applying Apple updates. I'm currently using Zxing.Net.Mobile -Version 2.0.4.46 and Zxing.Net.Mobile.Forms -Version 2.0.4.17 in my XF iOS app and it works great. I am also running Xamarin.iOS 9.6.2.2. Do I need to add NSCameraUsageDescription to info.plist in order for my app to work with iOS 10? Do I need to do anything else? Thanks in advance for the help and clarification.

@hharsha277
Copy link

Add the new entry to the info.plist worked for me.
Thank you.

@andrewchungxam
Copy link

Project worked after adding to Info.plist Property::"Privacy - Camera Usage Description" // Value::"Taking picture barcode".

@KratiChauhan
Copy link

Just sharing for someone novice like me....my key worked but only after cleaning the solution

@bertdd
Copy link

bertdd commented May 9, 2017

I am glad that I found this post and it did indeed resolve the problem for me too.
I don't use ZXing, but am decoding bar codes using the standard IOS bar code decoding.

Having said that: can anyone explain what the root cause of this is ? How can it be prevented in the future ... it seems like a coding mistake in the underlying infrastructure, someone must have added this description and forgot to check whether the string was initialized before using it. So a null pointer was probably encountered (just guessing here), was it Apple or Xamarin ?

The stack traces are not particularly useful, but I guess you need debug versions of the libraries to make that more descriptive.

BTW do we need to include the string in Localizable strings to make it readable for non-English users ?

@thedee
Copy link

thedee commented Jun 8, 2017

I am have IOS 9.3.5 installed and it works fine when i am debugging. When I run the app normal it crashes the application after the barcode is scanned. Any ideas why?

ZXing.Net.Mobile = 2.2.9
ZXing.Net.Mobile.Forms = 2.2.9
Xamarin.Forms = 2.3.4.231

Update:
I figure out the issue. For some reason it was calling the OnScanResult or the Device.BeginInvokeOnMainThread(() =>....... twice so then it tried doing the PopAsync twice. Not sure why it would do this but to fix I added a counter and only pop if counter == 1.

@Redth
Copy link
Owner

Redth commented Mar 13, 2020

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!

@Redth Redth closed this as completed Mar 13, 2020
@dnguyen2k
Copy link

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!

Hi Redth,
We have the need to include the scanner into our mobile app and one of my developers suggested to use ZXing.Net.Mobile scanner package. I have follow your example and suggestions from others and still haven't been able to get it to scan. I am using the latest version of xamarin forms and ZXing.Net.Mobile package. Do you have a workable version /example that I can try and see if I can spot what I did wrong? Any help is greatly appreciated.
Thanks,
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests