-
Notifications
You must be signed in to change notification settings - Fork 704
Description
I am in the process of updating a native xamarin ios app to a Microsoft.IOS .Net 6 app. I am using the ZXing.Net6.Mobile nuget which I used to replace the older ZXing.Net.Mobile .
The code being used was seamless as far as building but I am getting a null reference exception when calling the .Scan method. It's crashing all the way back to the Main application file. Just before the crash the camera does try to open.
This is the stack trace I am getting
object reference not set to instance of an object
at ZXing.Mobile.ZXingScannerView.SetupCaptureSession()
at ZXing.Mobile.ZXingScannerView.b__42_0()
at Foundation.NSActionDispatcher.Apply()
at Foundation.NSObject.InvokeOnMainThread(Action )
at ZXing.Mobile.ZXingScannerView.StartScanning(Action`1 scanResultHandler, MobileBarcodeScanningOptions options)
at ZXing.Mobile.ZXingScannerViewController.b__33_1()
at Foundation.NSAsyncActionDispatcher.Apply()
at UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr )
at UIKit.UIApplication.Main(String[] , Type , Type )
at DSDRouteManager.iOS.Application.Main(String[] args) in /Users/jamespridgen/Desktop/DSDRouteManager/DSDRouteManager.IOS/Main.cs:line
These are the keys I have in Info.plist
NSCameraUsageDescription
Can we use your camera
Privacy - Camera Usage Description
Taking picture barcode
Privacy - Photo Library Usage Description
Taking picture barcode
This is the code I am using to call the camera
var auth = AVCaptureDevice.GetAuthorizationStatus(AVAuthorizationMediaType.Video);
if (auth == AVAuthorizationStatus.NotDetermined)
{
if (AVCaptureDevice.RequestAccessForMediaTypeAsync(AVAuthorizationMediaType.Video).Result)
{
auth = AVCaptureDevice.GetAuthorizationStatus(AVAuthorizationMediaType.Video);
}
}
// camera access has been granted at this point
var cameraScanner = new MobileBarcodeScanner(this); // "this" is the UIViewController
var options = Util.GetMobileBarcodeScanningOptions();
var result = await cameraScanner.Scan(options,true); // crash happens here
Scanning options
return new MobileBarcodeScanningOptions()
{
AutoRotate = true,
PossibleFormats = new List<BarcodeFormat>()
{
BarcodeFormat.All_1D,
BarcodeFormat.QR_CODE,
BarcodeFormat.CODE_39,
BarcodeFormat.CODE_128,
BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E
}
};
Do I need some kind of initialization that the older nuget didn't require.
Any help would be much appreciated
James