@@ -8,12 +8,12 @@ import AVFoundation
88 */
99@objc ( CodeScannerPlugin)
1010public class CodeScannerPlugin : CAPPlugin , AVCaptureMetadataOutputObjectsDelegate , CAPBridgedPlugin {
11- public let identifier = " CodeScannerPlugin "
12- public let jsName = " CodeScanner "
11+ public let identifier = " CodeScannerPlugin "
12+ public let jsName = " CodeScanner "
1313 public let pluginMethods : [ CAPPluginMethod ] = [
14- CAPPluginMethod ( name: " present " , returnType: CAPPluginReturnPromise) ,
15- ]
16- // セッションのインスタンス生成
14+ CAPPluginMethod ( name: " present " , returnType: CAPPluginReturnPromise)
15+ ]
16+ // セッションのインスタンス生成
1717 let captureSession = AVCaptureSession ( )
1818 var videoLayer : AVCaptureVideoPreviewLayer ?
1919
@@ -101,7 +101,7 @@ public class CodeScannerPlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegat
101101 }
102102
103103 metadataOutput. metadataObjectTypes = metadataObjectTypes
104- metadataOutput. rectOfInterest = CGRect ( x: y, y: 1 - x- width, width: height, height: width)
104+ metadataOutput. rectOfInterest = CGRect ( x: y, y: 1 - x- width, width: height, height: width)
105105 self . isReady = true
106106 }
107107
@@ -147,7 +147,6 @@ public class CodeScannerPlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegat
147147 let closeGesture = UITapGestureRecognizer ( target: self , action: #selector( self . closeGesture) )
148148 btnClose. addGestureRecognizer ( closeGesture)
149149
150-
151150 DispatchQueue . global ( qos: . userInitiated) . async {
152151 if !self . captureSession. isRunning {
153152 self . captureSession. startRunning ( )
@@ -160,8 +159,7 @@ public class CodeScannerPlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegat
160159 }
161160 }
162161
163-
164- @objc func closeGesture( sender: UITapGestureRecognizer ) {
162+ @objc func closeGesture( sender: UITapGestureRecognizer ) {
165163 self . closeCamera ( )
166164 }
167165
@@ -177,7 +175,6 @@ public class CodeScannerPlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegat
177175 }
178176 }
179177
180-
181178 public func metadataOutput( _ output: AVCaptureMetadataOutput , didOutput metadataObjects: [ AVMetadataObject ] , from connection: AVCaptureConnection ) {
182179 for metadata in metadataObjects as! [ AVMetadataMachineReadableCodeObject ] {
183180 // コード内容の確認
@@ -200,26 +197,25 @@ public class CodeScannerPlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegat
200197 }
201198 }
202199
203-
204200 public func toggleLight( launch: Bool ) {
205201 DispatchQueue . main. async {
206- let avCaptureDevice = AVCaptureDevice . default ( for: AVMediaType . video)
207- if avCaptureDevice!. hasTorch, avCaptureDevice!. isTorchAvailable {
208- do {
209- try avCaptureDevice!. lockForConfiguration ( )
210-
211- if ( launch) {
212- print ( " light launch " )
213- avCaptureDevice!. torchMode = . on
214- } else {
215- print ( " light dissmiss " )
216- avCaptureDevice!. torchMode = . off
202+ let avCaptureDevice = AVCaptureDevice . default ( for: AVMediaType . video)
203+ if avCaptureDevice!. hasTorch, avCaptureDevice!. isTorchAvailable {
204+ do {
205+ try avCaptureDevice!. lockForConfiguration ( )
206+
207+ if launch {
208+ print ( " light launch " )
209+ avCaptureDevice!. torchMode = . on
210+ } else {
211+ print ( " light dissmiss " )
212+ avCaptureDevice!. torchMode = . off
213+ }
214+ avCaptureDevice!. unlockForConfiguration ( )
215+ } catch let error {
216+ print ( error)
217217 }
218- avCaptureDevice!. unlockForConfiguration ( )
219- } catch let error {
220- print ( error)
221218 }
222- }
223219 }
224- }
220+ }
225221}
0 commit comments