@@ -11,17 +11,15 @@ import DynamsoftBarcodeReader
11
11
@objc ( VisionCameraDBRPlugin)
12
12
public class VisionCameraDBRPlugin : NSObject , FrameProcessorPluginBase {
13
13
14
-
15
- private static var barcodeReader : DynamsoftBarcodeReader ! = nil
16
14
private static var mTemplate : String ! = nil
15
+ private static var mLicense : String ! = nil
17
16
private static let context = CIContext ( options: nil )
18
17
@objc
19
18
public static func callback( _ frame: Frame ! , withArgs args: [ Any ] ! ) -> Any ! {
20
19
let config = getConfig ( withArgs: args)
21
- if barcodeReader == nil {
22
- initDBR ( config: config)
23
- }
24
-
20
+
21
+ //for compatibility
22
+ initLicense ( config: config)
25
23
updateRuntimeSettingsWithTemplate ( config: config)
26
24
27
25
guard let imageBuffer = CMSampleBufferGetImageBuffer ( frame. buffer) else {
@@ -37,24 +35,30 @@ public class VisionCameraDBRPlugin: NSObject, FrameProcessorPluginBase {
37
35
var returned_results : [ Any ] = [ ]
38
36
let image = UIImage ( cgImage: cgImage)
39
37
// code goes here
40
- let results = try ? barcodeReader . decodeImage ( image)
38
+ let results = try ? VisionCameraDynamsoftBarcodeReader . dbr . decodeImage ( image)
41
39
let count = results? . count ?? 0
42
40
if count > 0 {
43
41
for index in 0 ..< count {
44
42
let tr = results![ index]
45
- returned_results. append ( wrapResult ( result: tr) )
43
+ returned_results. append ( VisionCameraDynamsoftBarcodeReader . wrapResult ( result: tr) )
46
44
}
47
45
print ( " Found barcodes " )
48
46
}
49
47
return returned_results
50
48
}
51
49
52
- static func initDBR( config: [ String : String ] ! ) {
53
- var license = " " ;
54
- license = config ? [ " license " ] ?? " DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ== "
55
- let initializer = BarcodeReaderInitializer ( ) ;
56
- barcodeReader = initializer. configurationDBR ( license: license)
50
+ static func initLicense( config: [ String : String ] ! ) {
51
+ if config ? [ " license " ] != nil {
52
+ let license = config ? [ " license " ] ?? " DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ== "
53
+ if license != mLicense {
54
+ mLicense = license
55
+ let initializer = BarcodeReaderInitializer ( )
56
+ initializer. initLicense ( license: license)
57
+ }
58
+ }
57
59
}
60
+
61
+
58
62
59
63
60
64
static func getConfig( withArgs args: [ Any ] ! ) -> [ String : String ] ! {
@@ -79,37 +83,19 @@ public class VisionCameraDBRPlugin: NSObject, FrameProcessorPluginBase {
79
83
}
80
84
81
85
if shouldUpdate {
82
- try ? barcodeReader . initRuntimeSettingsWithString ( template, conflictMode: EnumConflictMode . overwrite)
86
+ try ? VisionCameraDynamsoftBarcodeReader . dbr . initRuntimeSettingsWithString ( template, conflictMode: EnumConflictMode . overwrite)
83
87
mTemplate = template
84
88
}
85
89
86
90
} else {
87
91
if mTemplate != nil {
88
- try ? barcodeReader . resetRuntimeSettings ( )
92
+ try ? VisionCameraDynamsoftBarcodeReader . dbr . resetRuntimeSettings ( )
89
93
mTemplate = nil
90
94
}
91
95
}
92
96
}
93
97
94
- static func wrapResult( result: iTextResult ) -> Any {
95
- var map : [ String : Any ] = [ : ]
96
-
97
- map [ " barcodeText " ] = result. barcodeText
98
- map [ " barcodeFormat " ] = result. barcodeFormatString
99
- map [ " barcodeBytesBase64 " ] = result. barcodeBytes? . base64EncodedString ( )
100
-
101
- let points = result. localizationResult? . resultPoints as! [ CGPoint ]
102
- map [ " x1 " ] = points [ 0 ] . x
103
- map [ " x2 " ] = points [ 1 ] . x
104
- map [ " x3 " ] = points [ 2 ] . x
105
- map [ " x4 " ] = points [ 3 ] . x
106
- map [ " y1 " ] = points [ 0 ] . y
107
- map [ " y2 " ] = points [ 1 ] . y
108
- map [ " y3 " ] = points [ 2 ] . y
109
- map [ " y4 " ] = points [ 3 ] . y
110
-
111
- return map
112
- }
98
+
113
99
114
100
115
101
}
0 commit comments