Closed iMacX closed 4 years ago
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...
Ok, I found the solution.
Just add the NSCameraUsageDescription key to info.plist
<key>NSCameraUsageDescription</key>
<string>Can we use your camera</string>
Works. Thanks @iMacX
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_voidthis (object,intptr,intptr,intptr) <IL 0x00020, 0x000cc>
lokan82, do you think this problem might be related to https://github.com/Redth/ZXing.Net.Mobile/issues/422
Thanks @iMacX
the fix doesnt work for me either
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 :(
@NicolasDorier This bug has nothing to do with xamarin. It's a new requirement in iOS 10 introduced by Apple.
@iMacX so maybe at least a nice exception instead of a saddistic segfault error, would save some man-hours.
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.
=================================================================
I found that it works when debugging on a real device, when I use the simulator it dies with the error above.
@lokan82 we're getting the same crash on real devices. Are you seeing it work on real devices with or without the NSCameraUsageDescription
key?
With NSCameraUsageDescription added to info.plist
@iMacX and @lokan82 thanks for the tip, the NSCameraUsageDescription
fix worked for me on a real device (but not on the simulator).
Got exactly the same issue.
Does a fix is on the road?
Regards, Estema
Even with NSCameraUsageDescription added to info.plist it's not working for me.
@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!
@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.
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();
});
}
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
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
Add the new entry to the info.plist worked for me. Thank you.
Project worked after adding to Info.plist Property::"Privacy - Camera Usage Description" // Value::"Taking picture barcode".
Just sharing for someone novice like me....my key worked but only after cleaning the solution
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 ?
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.
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!
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
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