示例#1
0
        public AVMetadataObjectType ConvertToIOS(List <Helpers.BarcodeFormat> barcodeFormat)
        {
            AVMetadataObjectType types = AVMetadataObjectType.None;

            var mapping = new Dictionary <Helpers.BarcodeFormat, AVMetadataObjectType>
            {
                { Helpers.BarcodeFormat.Code128, AVMetadataObjectType.Code128Code },
                { Helpers.BarcodeFormat.Code39, AVMetadataObjectType.Code39Code },
                { Helpers.BarcodeFormat.Code93, AVMetadataObjectType.Code93Code },
                //{ Helpers.BarcodeFormat.Codabar, AVMetadataObjectType.codbar}, //사용 중단되고 있음.
                { Helpers.BarcodeFormat.DataMatrix, AVMetadataObjectType.DataMatrixCode },
                { Helpers.BarcodeFormat.Ean13, AVMetadataObjectType.EAN13Code },
                { Helpers.BarcodeFormat.Ean8, AVMetadataObjectType.EAN8Code },
                { Helpers.BarcodeFormat.Itf, AVMetadataObjectType.Interleaved2of5Code },
                { Helpers.BarcodeFormat.QrCode, AVMetadataObjectType.QRCode },
                { Helpers.BarcodeFormat.UpcA, AVMetadataObjectType.EAN13Code }, //UpcA = Ean13
                { Helpers.BarcodeFormat.UpcE, AVMetadataObjectType.UPCECode },
                { Helpers.BarcodeFormat.Pdf417, AVMetadataObjectType.PDF417Code },
                { Helpers.BarcodeFormat.AztecCode, AVMetadataObjectType.AztecCode },
                { Helpers.BarcodeFormat.Itf14, AVMetadataObjectType.ITF14Code }
            };

            foreach (Helpers.BarcodeFormat barcode in barcodeFormat)
            {
                if (mapping.ContainsKey(barcode))
                {
                    types |= mapping[barcode];
                }
            }

            return(types);
        }
示例#2
0
        public static AVMetadataObjectType ConvertToIOS(this IList <RebuyBarcode.BarcodeFormat> barcodeFormat)
        {
            AVMetadataObjectType types = AVMetadataObjectType.None;

            var mapping = new Dictionary <RebuyBarcode.BarcodeFormat, AVMetadataObjectType> {
                { RebuyBarcode.BarcodeFormat.Code128, AVMetadataObjectType.Code128Code },
                { RebuyBarcode.BarcodeFormat.Code39, AVMetadataObjectType.Code39Code },
                { RebuyBarcode.BarcodeFormat.Code93, AVMetadataObjectType.Code93Code },
                { RebuyBarcode.BarcodeFormat.DataMatrix, AVMetadataObjectType.DataMatrixCode },
                { RebuyBarcode.BarcodeFormat.Ean13, AVMetadataObjectType.EAN13Code },
                { RebuyBarcode.BarcodeFormat.Ean8, AVMetadataObjectType.EAN8Code },
                { RebuyBarcode.BarcodeFormat.Itf, AVMetadataObjectType.ITF14Code },
                { RebuyBarcode.BarcodeFormat.Pdf417, AVMetadataObjectType.PDF417Code },
                { RebuyBarcode.BarcodeFormat.QrCode, AVMetadataObjectType.QRCode },
                { RebuyBarcode.BarcodeFormat.UpcE, AVMetadataObjectType.UPCECode },
                { RebuyBarcode.BarcodeFormat.Intervealed2of5, AVMetadataObjectType.Interleaved2of5Code },
            };

            foreach (RebuyBarcode.BarcodeFormat barcode in barcodeFormat)
            {
                if (mapping.ContainsKey(barcode))
                {
                    types |= mapping[barcode];
                }
            }

            return(types);
        }
示例#3
0
        public void MetadataObjectTypesTest()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false);

            if (Runtime.Arch != Arch.DEVICE)
            {
                Assert.Ignore("This test only runs on device (requires camera access)");
            }

            TestRuntime.RequestCameraPermission(AVMediaType.Video, true);

            using (var captureSession = new AVCaptureSession()) {
                using (var videoDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video)) {
                    NSError error;
                    using (var videoInput = new AVCaptureDeviceInput(videoDevice, out error)) {
                        if (captureSession.CanAddInput(videoInput))
                        {
                            captureSession.AddInput(videoInput);
                        }

                        using (var metadataOutput = new AVCaptureMetadataOutput()) {
                            if (captureSession.CanAddOutput(metadataOutput))
                            {
                                captureSession.AddOutput(metadataOutput);
                            }

                            AVMetadataObjectType all = AVMetadataObjectType.None;
                            foreach (AVMetadataObjectType val in Enum.GetValues(typeof(AVMetadataObjectType)))
                            {
                                switch (val)
                                {
                                case AVMetadataObjectType.CatBody:
                                case AVMetadataObjectType.DogBody:
                                case AVMetadataObjectType.HumanBody:
                                case AVMetadataObjectType.SalientObject:
                                    // fail *and crash* on iOS 8 (at least on 32bits devices)
                                    if (!TestRuntime.CheckXcodeVersion(11, 0))
                                    {
                                        continue;
                                    }
                                    // xcode 12 beta 1 on device
                                    if ((Runtime.Arch == Arch.DEVICE) && TestRuntime.CheckXcodeVersion(12, 0))
                                    {
                                        continue;
                                    }
                                    break;
                                }
                                metadataOutput.MetadataObjectTypes = val;
                                all |= val;
                                Assert.AreEqual(val, metadataOutput.MetadataObjectTypes, val.ToString());
                            }
                            metadataOutput.MetadataObjectTypes = all;
                            Assert.AreEqual(all, metadataOutput.MetadataObjectTypes, all.ToString());
                        }
                    }
                }
            }
        }
        internal static NSString EnumToObject(AVMetadataObjectType val)
        {
            switch (val)
            {
            case AVMetadataObjectType.None:
                return(null);

            case AVMetadataObjectType.Face:
                return(AVMetadataObject.TypeFace);

            case AVMetadataObjectType.AztecCode:
                return(AVMetadataObject.TypeAztecCode);

            case AVMetadataObjectType.Code128Code:
                return(AVMetadataObject.TypeCode128Code);

            case AVMetadataObjectType.Code39Code:
                return(AVMetadataObject.TypeCode39Code);

            case AVMetadataObjectType.Code39Mod43Code:
                return(AVMetadataObject.TypeCode39Mod43Code);

            case AVMetadataObjectType.Code93Code:
                return(AVMetadataObject.TypeCode93Code);

            case AVMetadataObjectType.EAN13Code:
                return(AVMetadataObject.TypeEAN13Code);

            case AVMetadataObjectType.EAN8Code:
                return(AVMetadataObject.TypeEAN8Code);

            case AVMetadataObjectType.PDF417Code:
                return(AVMetadataObject.TypePDF417Code);

            case AVMetadataObjectType.QRCode:
                return(AVMetadataObject.TypeQRCode);

            case AVMetadataObjectType.UPCECode:
                return(AVMetadataObject.TypeUPCECode);

            case AVMetadataObjectType.Interleaved2of5Code:
                return(AVMetadataObject.TypeInterleaved2of5Code);

            case AVMetadataObjectType.ITF14Code:
                return(AVMetadataObject.TypeITF14Code);

            case AVMetadataObjectType.DataMatrixCode:
                return(AVMetadataObject.TypeDataMatrixCode);

            default:
                throw new ArgumentOutOfRangeException(string.Format("Unexpected AVMetadataObjectType: {0}", val));
            }
        }
示例#5
0
        public void MetadataObjectTypesTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(8, 0))
            {
                Assert.Ignore("Test only works correctly in iOS 8+");
            }

            if (Runtime.Arch != Arch.DEVICE)
            {
                Assert.Ignore("This test only runs on device (requires camera access)");
            }

            var auth = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            switch (auth)
            {
            case AVAuthorizationStatus.Restricted:
            case AVAuthorizationStatus.Denied:
                Assert.Fail("This test requires access to the camera, but the app has been denied access.");
                break;
            }

            using (var captureSession = new AVCaptureSession()) {
                using (var videoDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video)) {
                    NSError error;
                    using (var videoInput = new AVCaptureDeviceInput(videoDevice, out error)) {
                        if (captureSession.CanAddInput(videoInput))
                        {
                            captureSession.AddInput(videoInput);
                        }

                        using (var metadataOutput = new AVCaptureMetadataOutput()) {
                            if (captureSession.CanAddOutput(metadataOutput))
                            {
                                captureSession.AddOutput(metadataOutput);
                            }

                            AVMetadataObjectType all = AVMetadataObjectType.None;
                            foreach (AVMetadataObjectType val in Enum.GetValues(typeof(AVMetadataObjectType)))
                            {
                                metadataOutput.MetadataObjectTypes = val;
                                all |= val;
                                Assert.AreEqual(val, metadataOutput.MetadataObjectTypes, val.ToString());
                            }
                            metadataOutput.MetadataObjectTypes = all;
                            Assert.AreEqual(all, metadataOutput.MetadataObjectTypes, all.ToString());
                        }
                    }
                }
            }
        }
        private AVMetadataObjectType XamBarcodeFormatToIos(XamBarcodeFormat barcodeFormat)
        {
            AVMetadataObjectType targetFormat = AVMetadataObjectType.None;

            if ((barcodeFormat & XamBarcodeFormat.Code128) == XamBarcodeFormat.Code128)
            {
                targetFormat |= AVMetadataObjectType.Code128Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.Code39) == XamBarcodeFormat.Code39)
            {
                targetFormat |= AVMetadataObjectType.Code39Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.Code93) == XamBarcodeFormat.Code93)
            {
                targetFormat |= AVMetadataObjectType.Code93Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.DataMatrix) == XamBarcodeFormat.DataMatrix)
            {
                targetFormat |= AVMetadataObjectType.DataMatrixCode;
            }
            if ((barcodeFormat & XamBarcodeFormat.Ean13) == XamBarcodeFormat.Ean13)
            {
                targetFormat |= AVMetadataObjectType.EAN13Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.Ean8) == XamBarcodeFormat.Ean8)
            {
                targetFormat |= AVMetadataObjectType.EAN8Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.Itf) == XamBarcodeFormat.Itf)
            {
                targetFormat |= AVMetadataObjectType.ITF14Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.QrCode) == XamBarcodeFormat.QrCode)
            {
                targetFormat |= AVMetadataObjectType.QRCode;
            }
            if ((barcodeFormat & XamBarcodeFormat.UpcE) == XamBarcodeFormat.UpcE)
            {
                targetFormat |= AVMetadataObjectType.UPCECode;
            }
            if ((barcodeFormat & XamBarcodeFormat.Pdf417) == XamBarcodeFormat.Pdf417)
            {
                targetFormat |= AVMetadataObjectType.PDF417Code;
            }
            if ((barcodeFormat & XamBarcodeFormat.Aztec) == XamBarcodeFormat.Aztec)
            {
                targetFormat |= AVMetadataObjectType.AztecCode;
            }

            return(targetFormat);
        }
示例#7
0
        /// <summary>
        /// 바코드 스캐너 서비스를 생성합니다.
        /// </summary>
        /// <param name="barcodeFormat">인식할 바코드 포멧</param>
        /// <param name="sessionPreset">해상도</param>
        /// <returns></returns>
        public static ScannerService Create(AVMetadataObjectType barcodeFormat, NSString sessionPreset)
        {
            var ss     = new ScannerService();
            var result = ss.InitScanner(barcodeFormat, sessionPreset);

            if (result)
            {
                return(ss);
            }
            else
            {
                ss.Dispose();
                return(null);
            }
        }
示例#8
0
        public static IEnumerable <AVMetadataObjectType> GetFlags(this AVMetadataObjectType value)
        {
            var shifts = 0;
            var val    = (ulong)value;

            while (val != 0)
            {
                if ((val & 1) == 1)
                {
                    yield return((AVMetadataObjectType)(1 << shifts));
                }
                shifts++;
                val >>= 1;
            }
        }
        internal static AVMetadataObjectType ArrayToEnum(NSString[] arr)
        {
            AVMetadataObjectType rv = AVMetadataObjectType.None;

            if (arr == null || arr.Length == 0)
            {
                return(rv);
            }

            foreach (var str in arr)
            {
                rv |= ObjectToEnum(str);
            }

            return(rv);
        }
示例#10
0
        /// <summary>
        /// AV Foundation 바코드 포멧을 Tmon 바코드 포멧으로 변환
        /// </summary>
        /// <param name="format">AV Foundation 바코드 포멧</param>
        /// <returns>Tmon 바코드 포멧</returns>
        public static Enums.BarcodeFormat ToTmonFormat(this AVMetadataObjectType format)
        {
            if (format == AVMetadataObjectType.Interleaved2of5Code || format == AVMetadataObjectType.ITF14Code)
            {
                format = COMBINED_ITF;
            }

            if (_MappingDic.ContainsKey(format))
            {
                return(_MappingDic[format]);
            }
            else
            {
                return(Enums.BarcodeFormat.Unknown);
            }
        }
        public static RebuyBarcode.BarcodeFormat ConvertToPcl(this AVMetadataObjectType type)
        {
            var mapping = new Dictionary <AVMetadataObjectType, RebuyBarcode.BarcodeFormat> {
                { AVMetadataObjectType.Code128Code, RebuyBarcode.BarcodeFormat.Code128 },
                { AVMetadataObjectType.Code39Code, RebuyBarcode.BarcodeFormat.Code39 },
                { AVMetadataObjectType.Code93Code, RebuyBarcode.BarcodeFormat.Code93 },
                { AVMetadataObjectType.DataMatrixCode, RebuyBarcode.BarcodeFormat.DataMatrix },
                { AVMetadataObjectType.EAN13Code, RebuyBarcode.BarcodeFormat.Ean13 },
                { AVMetadataObjectType.EAN8Code, RebuyBarcode.BarcodeFormat.Ean8 },
                { AVMetadataObjectType.ITF14Code, RebuyBarcode.BarcodeFormat.Itf },
                { AVMetadataObjectType.PDF417Code, RebuyBarcode.BarcodeFormat.Pdf417 },
                { AVMetadataObjectType.QRCode, RebuyBarcode.BarcodeFormat.QrCode },
                { AVMetadataObjectType.UPCECode, RebuyBarcode.BarcodeFormat.UpcE },
            };

            return(!mapping.ContainsKey(type) ? RebuyBarcode.BarcodeFormat.Unknown : mapping[type]);
        }
示例#12
0
        internal static NSString[] EnumToArray(AVMetadataObjectType value)
        {
            if (value == AVMetadataObjectType.None)
                return null;

            var rv = new List<NSString> ();
            var val = (ulong) value;
            var shifts = 0;

            while (val != 0) {
                if ((val & 0x1) == 0x1)
                    rv.Add (EnumToObject ((AVMetadataObjectType) (0x1UL << shifts)));
                val >>= 1;
                shifts++;
            }

            return rv.ToArray ();
        }
示例#13
0
        public void MetadataObjectTypesTest()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(8, 0))
            {
                Assert.Ignore("Test only works correctly in iOS 8+");
            }

            if (Runtime.Arch != Arch.DEVICE)
            {
                Assert.Ignore("This test only runs on device (requires camera access)");
            }

            TestRuntime.RequestCameraPermission(AVMediaType.Video, true);

            using (var captureSession = new AVCaptureSession()) {
                using (var videoDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video)) {
                    NSError error;
                    using (var videoInput = new AVCaptureDeviceInput(videoDevice, out error)) {
                        if (captureSession.CanAddInput(videoInput))
                        {
                            captureSession.AddInput(videoInput);
                        }

                        using (var metadataOutput = new AVCaptureMetadataOutput()) {
                            if (captureSession.CanAddOutput(metadataOutput))
                            {
                                captureSession.AddOutput(metadataOutput);
                            }

                            AVMetadataObjectType all = AVMetadataObjectType.None;
                            foreach (AVMetadataObjectType val in Enum.GetValues(typeof(AVMetadataObjectType)))
                            {
                                metadataOutput.MetadataObjectTypes = val;
                                all |= val;
                                Assert.AreEqual(val, metadataOutput.MetadataObjectTypes, val.ToString());
                            }
                            metadataOutput.MetadataObjectTypes = all;
                            Assert.AreEqual(all, metadataOutput.MetadataObjectTypes, all.ToString());
                        }
                    }
                }
            }
        }
        internal static NSString[] EnumToArray(AVMetadataObjectType value)
        {
            if (value == AVMetadataObjectType.None)
            {
                return(null);
            }

            var rv     = new List <NSString> ();
            var val    = (ulong)value;
            var shifts = 0;

            while (val != 0)
            {
                if ((val & 0x1) == 0x1)
                {
                    rv.Add(EnumToObject((AVMetadataObjectType)(0x1UL << shifts)));
                }
                val >>= 1;
                shifts++;
            }

            return(rv.ToArray());
        }
示例#15
0
 internal static NSString EnumToObject(AVMetadataObjectType val)
 {
     switch (val) {
     case AVMetadataObjectType.None:
         return null;
     case AVMetadataObjectType.Face:
         return AVMetadataObject.TypeFace;
     case AVMetadataObjectType.AztecCode:
         return AVMetadataObject.TypeAztecCode;
     case AVMetadataObjectType.Code128Code:
         return AVMetadataObject.TypeCode128Code;
     case AVMetadataObjectType.Code39Code:
         return AVMetadataObject.TypeCode39Code;
     case AVMetadataObjectType.Code39Mod43Code:
         return AVMetadataObject.TypeCode39Mod43Code;
     case AVMetadataObjectType.Code93Code:
         return AVMetadataObject.TypeCode93Code;
     case AVMetadataObjectType.EAN13Code:
         return AVMetadataObject.TypeEAN13Code;
     case AVMetadataObjectType.EAN8Code:
         return AVMetadataObject.TypeEAN8Code;
     case AVMetadataObjectType.PDF417Code:
         return AVMetadataObject.TypePDF417Code;
     case AVMetadataObjectType.QRCode:
         return AVMetadataObject.TypeQRCode;
     case AVMetadataObjectType.UPCECode:
         return AVMetadataObject.TypeUPCECode;
     case AVMetadataObjectType.Interleaved2of5Code:
         return AVMetadataObject.TypeInterleaved2of5Code;
     case AVMetadataObjectType.ITF14Code:
         return AVMetadataObject.TypeITF14Code;
     case AVMetadataObjectType.DataMatrixCode:
         return AVMetadataObject.TypeDataMatrixCode;
     default:
         throw new ArgumentOutOfRangeException (string.Format ("Unexpected AVMetadataObjectType: {0}", val));
     }
 }
        AVMetadataObjectType AVCaptureBarcodeFormatFromZXingBarcodeFormat(BarcodeFormat zxingBarcodeFormat)
        {
            AVMetadataObjectType formats = AVMetadataObjectType.None;

            switch (zxingBarcodeFormat)
            {
            case BarcodeFormat.AZTEC:
                formats |= AVMetadataObjectType.AztecCode;
                break;

            case BarcodeFormat.CODE_128:
                formats |= AVMetadataObjectType.Code128Code;
                break;

            case BarcodeFormat.CODE_39:
                formats |= AVMetadataObjectType.Code39Code;
                formats |= AVMetadataObjectType.Code39Mod43Code;
                break;

            case BarcodeFormat.CODE_93:
                formats |= AVMetadataObjectType.Code93Code;
                break;

            case BarcodeFormat.EAN_13:
                formats |= AVMetadataObjectType.EAN13Code;
                break;

            case BarcodeFormat.EAN_8:
                formats |= AVMetadataObjectType.EAN8Code;
                break;

            case BarcodeFormat.PDF_417:
                formats |= AVMetadataObjectType.PDF417Code;
                break;

            case BarcodeFormat.QR_CODE:
                formats |= AVMetadataObjectType.QRCode;
                break;

            case BarcodeFormat.UPC_E:
                formats |= AVMetadataObjectType.UPCECode;
                break;

            case BarcodeFormat.All_1D:
                formats |= AVMetadataObjectType.UPCECode;
                formats |= AVMetadataObjectType.EAN13Code;
                formats |= AVMetadataObjectType.EAN8Code;
                formats |= AVMetadataObjectType.Code39Code;
                formats |= AVMetadataObjectType.Code39Mod43Code;
                formats |= AVMetadataObjectType.Code93Code;
                break;

            case BarcodeFormat.DATA_MATRIX:
                formats |= AVMetadataObjectType.DataMatrixCode;
                break;

            case BarcodeFormat.ITF:
                formats |= AVMetadataObjectType.ITF14Code;
                break;

            case BarcodeFormat.CODABAR:
            case BarcodeFormat.MAXICODE:
            case BarcodeFormat.MSI:
            case BarcodeFormat.PLESSEY:
            case BarcodeFormat.RSS_14:
            case BarcodeFormat.RSS_EXPANDED:
            case BarcodeFormat.UPC_A:
                //TODO: Throw exception?
                break;
            }

            return(formats);
        }
示例#17
0
        /// <summary>
        /// 스캐너를 초기화합니다.
        /// </summary>
        /// <param name="barcodeFormat">인식할 바코드 포멧</param>
        /// <param name="sessionPreset">해상도</param>
        /// <returns></returns>
        private bool InitScanner(AVMetadataObjectType barcodeFormat, NSString sessionPreset)
        {
            // 카메라 접근 권한 확인
            if (!IsCameraAuthorized)
            {
                this.Write("카메라 사용이 허용되지 않습니다.");
                return(false);
            }

            // 후면 카메라를 캡처할 장치로 설정
            Device = AVCaptureDevice
                     .DevicesWithMediaType(AVMediaType.Video)
                     .FirstOrDefault(e => e.Position == AVCaptureDevicePosition.Back);
            if (Device == null)
            {
                this.Write("후면 카메라가 없습니다.");
                return(false);
            }

            // 입력 설정
            Input = AVCaptureDeviceInput.FromDevice(Device);
            if (Input == null)
            {
                this.Write("AVCaptureDeviceInput이 null 입니다.");
                return(false);
            }

            // 출력 설정
            CaptureDelegate = new CaptureDelegate((metadataObjects) =>
            {
                if (BarcodeDetected == null)
                {
                    return;
                }

                foreach (var metadata in metadataObjects)
                {
                    var data = ((AVMetadataMachineReadableCodeObject)metadata).StringValue;
                    BarcodeDetected?.Invoke(new BarcodeData(metadata.Type.ToTmonFormat(), data));
                }
            });
            Output = new AVCaptureMetadataOutput();
            Output.SetDelegate(CaptureDelegate, DispatchQueue.MainQueue);

            // 세션 설정
            Session = new AVCaptureSession()
            {
                SessionPreset = sessionPreset,
            };
            Session.AddInput(Input);
            Session.AddOutput(Output);

            // 검출할 바코드 포멧 설정(중요 : 반드시 세션 설정 뒤에 와야함)
            Output.MetadataObjectTypes = barcodeFormat;

            // 프리뷰어 설정
            Previewer              = AVCaptureVideoPreviewLayer.FromSession(Session);
            Previewer.Frame        = CGRect.Empty;
            Previewer.VideoGravity = AVLayerVideoGravity.ResizeAspectFill;
            Previewer.Connection.VideoOrientation = DeviceOrientation;

            return(true);
        }
示例#18
0
        private void ConfigureSession()
        {
            if (setupResult == SessionSetupResult.Success)
            {
                this.session.BeginConfiguration();

                // Add video input
                // Choose the back wide angle camera if available, otherwise default to the front wide angle camera
                defaultVideoDevice = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInWideAngleCamera, AVMediaType.Video, AVCaptureDevicePosition.Back) ??
                                     AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInWideAngleCamera, AVMediaType.Video, AVCaptureDevicePosition.Front) ??
                                     null;

                if (defaultVideoDevice == null)
                {
                    Console.WriteLine("Could not get video device");
                    this.setupResult = SessionSetupResult.ConfigurationFailed;
                    this.session.CommitConfiguration();
                    return;
                }

                NSError error;
                var     videoDeviceInput = AVCaptureDeviceInput.FromDevice(defaultVideoDevice, out error);
                if (this.session.CanAddInput(videoDeviceInput))
                {
                    this.session.AddInput(videoDeviceInput);
                    this.videoDeviceInput = videoDeviceInput;

                    if (this.videoDeviceInput.Device.LockForConfiguration(out error))
                    {
                        if (this.videoDeviceInput.Device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
                        {
                            this.videoDeviceInput.Device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                        }

                        if (this.videoDeviceInput.Device.AutoFocusRangeRestrictionSupported)
                        {
                            this.videoDeviceInput.Device.AutoFocusRangeRestriction = AVCaptureAutoFocusRangeRestriction.Near; //Near는 바코드 스캔용
                        }

                        if (this.videoDeviceInput.Device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
                        {
                            this.videoDeviceInput.Device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                        }

                        //Console.WriteLine(this.videoDeviceInput.Device.ExposureMode.ToString());
                        this.videoDeviceInput.Device.UnlockForConfiguration();
                    }


                    this.session.SessionPreset = AVCaptureSession.Preset1920x1080;
                    //this.session.SessionPreset = AVCaptureSession.Preset1280x720;

                    DispatchQueue.MainQueue.DispatchAsync(() =>
                    {
                        // Why are we dispatching this to the main queue?
                        // Because AVCaptureVideoPreviewLayer is the backing layer for PreviewView and UIView
                        // can only be manipulated on the main thread
                        // Note: As an exception to the above rule, it's not necessary to serialize video orientation changed
                        // on the AVCaptureVideoPreviewLayer's connection with other session manipulation
                        //
                        // Use the status bar orientation as the internal video orientation. Subsequent orientation changes are
                        // handled by CameraViewController.ViewWillTransition(to:with:).

                        var initialVideoOrientation = AVCaptureVideoOrientation.Portrait;
                        var statusBarOrientation    = UIApplication.SharedApplication.StatusBarOrientation;
                        if (statusBarOrientation != UIInterfaceOrientation.Unknown)
                        {
                            AVCaptureVideoOrientation videoOrintation;
                            if (Enum.TryParse(statusBarOrientation.ToString(), out videoOrintation))
                            {
                                initialVideoOrientation = videoOrintation;
                            }
                        }

                        this.PreviewView.VideoPreviewLayer.Connection.VideoOrientation = initialVideoOrientation;
                    });
                }
                else if (error != null)
                {
                    Console.WriteLine($"Could not create video device input: {error}");
                    this.setupResult = SessionSetupResult.ConfigurationFailed;
                    this.session.CommitConfiguration();
                    return;
                }
                else
                {
                    Console.WriteLine("Could not add video device input to the session");
                    this.setupResult = SessionSetupResult.ConfigurationFailed;
                    this.session.CommitConfiguration();

                    return;
                }


                // Add metadata output
                if (this.session.CanAddOutput(metadataOutput))
                {
                    this.session.AddOutput(metadataOutput);

                    // Set this view controller as the delegate for metadata objects
                    this.metadataOutput.SetDelegate(this, this.metadataObjectsQueue);

                    AVMetadataObjectType supportBarcodeFormat = AVMetadataObjectType.None;

                    //hm.ji, 지원하는 바코드 지정, Defualt로 모든바코드
                    // this.metadataOutput.MetadataObjectTypes = this.metadataOutput.AvailableMetadataObjectTypes; // Use all metadata object types by default

                    string jsonList = Xamarin.Forms.Application.Current.Properties["SupportBarcodeFormat"].ToString();
                    List <Helpers.BarcodeFormat> tmpList = JsonConvert.DeserializeObject <List <Helpers.BarcodeFormat> >(jsonList);

                    supportBarcodeFormat = ConvertToIOS(tmpList);

                    this.metadataOutput.MetadataObjectTypes = supportBarcodeFormat;

                    //this.metadataOutput.MetadataObjectTypes = AVMetadataObjectType.AztecCode |
                    //                                          AVMetadataObjectType.Code128Code |
                    //                                          AVMetadataObjectType.Code39Code |
                    //                                          AVMetadataObjectType.Code39Mod43Code |
                    //                                          AVMetadataObjectType.Code93Code |
                    //                                          AVMetadataObjectType.EAN13Code |
                    //                                          AVMetadataObjectType.EAN8Code |
                    //                                          AVMetadataObjectType.PDF417Code |
                    //                                          AVMetadataObjectType.QRCode |
                    //                                          AVMetadataObjectType.UPCECode |
                    //                                          AVMetadataObjectType.Interleaved2of5Code |
                    //                                          AVMetadataObjectType.ITF14Code |
                    //                                          AVMetadataObjectType.DataMatrixCode;
                    // Set an initial rect of interest that is 80% of the views's shortest side
                    // and 25% of the longest side. This means that the region on interest will
                    // appear in the same spot regardless of whether the app starts in portrait
                    // or landscape

                    //var width = 0.7; //높이 기본값 : 0.25, 전체 사용하려면 1
                    //var height = 0.9; //넓이, 초기 값은 0.8
                    //var x = (1 - width) / 2;
                    //var y = (1 - height) / 2;
                    //var initialRectOfInterest = new CGRect(x + 0.01, y, width, height);

                    CGRect initialRectOfInterest;

                    if (Settings.ScanMode.Equals("FULL"))
                    {
                        var width  = 1.0; //높이 기본값 : 0.25, 전체 사용하려면 1
                        var height = 1.0; //넓이, 초기 값은 0.8
                        var x      = (1 - width) / 2;
                        var y      = (1 - height) / 2;
                        initialRectOfInterest = new CGRect(x, y, width, height);
                    }
                    else if (Settings.ScanMode.Equals("WIDE"))
                    {
                        var width  = 0.25; //높이 기본값 : 0.25, 전체 사용하려면 1
                        var height = 0.9;  //넓이, 초기 값은 0.8
                        var x      = (1 - width) / 2;
                        var y      = (1 - height) / 2;
                        initialRectOfInterest = new CGRect(x, y, width, height);
                    }
                    else if (Settings.ScanMode.Equals("SPLIT"))
                    {
                        var width  = 0.15;
                        var height = 1.0;
                        var x      = (1 - width) / 2;
                        var y      = (1 - height) / 2;
                        initialRectOfInterest = new CGRect(0.09, 0, width, height);
                    }
                    else
                    {
                        var width  = 0.15;
                        var height = 1.0;
                        var x      = (1 - width) / 2;
                        var y      = (1 - height) / 2;
                        initialRectOfInterest = new CGRect(0.09, 0, width, height);
                    }

                    this.metadataOutput.RectOfInterest = initialRectOfInterest;

                    DispatchQueue.MainQueue.DispatchAsync(() =>
                    {
                        var initialRegionOfInterest = this.PreviewView.VideoPreviewLayer.MapToLayerCoordinates(initialRectOfInterest);
                        this.PreviewView.SetRegionOfInterestWithProposedRegionOfInterest(initialRegionOfInterest);
                    });
                }
                else
                {
                    Console.WriteLine("Could not add metadata output to the session");
                    this.setupResult = SessionSetupResult.ConfigurationFailed;
                    this.session.CommitConfiguration();

                    return;
                }

                this.session.CommitConfiguration();
            }
        }