Skip to content

Commit 0475617

Browse files
committed
Update code for iOS
1 parent 42fada5 commit 0475617

File tree

5 files changed

+117
-161
lines changed

5 files changed

+117
-161
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ A Flutter wrapper for the **Dynamsoft Capture Vision SDK**, featuring document d
2424
- ✅ Android
2525
- ✅ iOS
2626

27-
Add camera and microphone usage descriptions to `ios/Runner/Info.plist`:
27+
- Add camera and microphone usage descriptions to `ios/Runner/Info.plist`:
2828

29-
```xml
30-
<key>NSCameraUsageDescription</key>
31-
<string>Can I use the camera please?</string>
32-
<key>NSMicrophoneUsageDescription</key>
33-
<string>Can I use the mic please?</string>
34-
```
29+
```xml
30+
<key>NSCameraUsageDescription</key>
31+
<string>Can I use the camera please?</string>
32+
<key>NSMicrophoneUsageDescription</key>
33+
<string>Can I use the mic please?</string>
34+
```
35+
36+
- Minimum deployment target: iOS 13.0 or later
3537

3638
- ✅ Web
3739

@@ -64,8 +66,6 @@ A Flutter wrapper for the **Dynamsoft Capture Vision SDK**, featuring document d
6466
flutter run -d windows # Run on Windows
6567
flutter run # Run on default connected device (e.g., Android)
6668
```
67-
68-
6969

7070
## API Reference
7171

example/ios/Podfile.lock

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,10 @@
11
PODS:
22
- camera_avfoundation (0.0.1):
33
- Flutter
4-
- DynamsoftBarcodeReader (10.4.30)
5-
- DynamsoftCameraEnhancer (4.2.24)
6-
- DynamsoftCaptureVisionBundle (2.6.1004):
7-
- DynamsoftBarcodeReader (= 10.4.30)
8-
- DynamsoftCameraEnhancer (= 4.2.24)
9-
- DynamsoftCaptureVisionRouter (= 2.4.30)
10-
- DynamsoftCodeParser (= 2.4.30)
11-
- DynamsoftCodeParserDedicator (= 1.2.30)
12-
- DynamsoftCore (= 3.4.30)
13-
- DynamsoftDocumentNormalizer (= 2.6.10)
14-
- DynamsoftImageProcessing (= 2.4.30)
15-
- DynamsoftLabelRecognizer (= 3.4.30)
16-
- DynamsoftLicense (= 3.4.40)
17-
- DynamsoftNeuralNetwork (= 1.0.20)
18-
- DynamsoftUtility (= 1.4.30)
19-
- DynamsoftCaptureVisionRouter (2.4.30)
20-
- DynamsoftCodeParser (2.4.30)
21-
- DynamsoftCodeParserDedicator (1.2.30)
22-
- DynamsoftCore (3.4.30)
23-
- DynamsoftDocumentNormalizer (2.6.10)
24-
- DynamsoftImageProcessing (2.4.30)
25-
- DynamsoftLabelRecognizer (3.4.30)
26-
- DynamsoftLicense (3.4.40)
27-
- DynamsoftNeuralNetwork (1.0.20)
28-
- DynamsoftUtility (1.4.30)
4+
- DynamsoftCaptureVisionBundle (3.0.3000)
295
- Flutter (1.0.0)
306
- flutter_document_scan_sdk (0.3.0):
31-
- DynamsoftCaptureVisionBundle (= 2.6.1004)
7+
- DynamsoftCaptureVisionBundle (= 3.0.3000)
328
- Flutter
339
- flutter_exif_rotation (0.3.0):
3410
- Flutter
@@ -58,19 +34,7 @@ DEPENDENCIES:
5834

5935
SPEC REPOS:
6036
trunk:
61-
- DynamsoftBarcodeReader
62-
- DynamsoftCameraEnhancer
6337
- DynamsoftCaptureVisionBundle
64-
- DynamsoftCaptureVisionRouter
65-
- DynamsoftCodeParser
66-
- DynamsoftCodeParserDedicator
67-
- DynamsoftCore
68-
- DynamsoftDocumentNormalizer
69-
- DynamsoftImageProcessing
70-
- DynamsoftLabelRecognizer
71-
- DynamsoftLicense
72-
- DynamsoftNeuralNetwork
73-
- DynamsoftUtility
7438

7539
EXTERNAL SOURCES:
7640
camera_avfoundation:
@@ -94,21 +58,9 @@ EXTERNAL SOURCES:
9458

9559
SPEC CHECKSUMS:
9660
camera_avfoundation: be3be85408cd4126f250386828e9b1dfa40ab436
97-
DynamsoftBarcodeReader: b1925cf91cea404444c8eccf9045f5bd78a65d51
98-
DynamsoftCameraEnhancer: 18628b6cd6169d35b5579424cdfab37e1b8ca7a4
99-
DynamsoftCaptureVisionBundle: bb5d6c044784ce56b8b3615eed6cb88db695aa67
100-
DynamsoftCaptureVisionRouter: 4e2fb20b7f0aae3b8709b6ff56713decb599e4ea
101-
DynamsoftCodeParser: 7a8118c0bcd21bc849aaf7427f4088c2ea15d9a6
102-
DynamsoftCodeParserDedicator: baa514940d7f5310e4a5f5d04eb59bb8282c1c8a
103-
DynamsoftCore: 7b4ba6658f14d99aab9cc8e6ff2bc847909103ff
104-
DynamsoftDocumentNormalizer: 5aa9f3c0465face2159862398970142a8b451b29
105-
DynamsoftImageProcessing: 9c8e8deae9165693ec4ba4499a835a5609659fbb
106-
DynamsoftLabelRecognizer: e05eed966b67d99dc8189ef74383a7454de37377
107-
DynamsoftLicense: 4eabe8e077a64b38c8fdcf6177236bc018bac9a0
108-
DynamsoftNeuralNetwork: 281373d04b236f4616f2f607b6266f0393d906e5
109-
DynamsoftUtility: 0cea6058495725a9bdfff664f952785d81ab274e
61+
DynamsoftCaptureVisionBundle: 1935e3efc70db1b7c6cab19dfe420c3e43dbe1a0
11062
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
111-
flutter_document_scan_sdk: fd430a5d3597db3373a0a28eb65f319f8a28aa10
63+
flutter_document_scan_sdk: 3074bc572d0116e3e9089c604c4495e396007e4c
11264
flutter_exif_rotation: 5406455759acacf1f7b1b83e85dbb545340d6e9c
11365
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
11466
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@
470470
DEVELOPMENT_TEAM = 29QXPN337R;
471471
ENABLE_BITCODE = NO;
472472
INFOPLIST_FILE = Runner/Info.plist;
473+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
473474
LD_RUNPATH_SEARCH_PATHS = (
474475
"$(inherited)",
475476
"@executable_path/Frameworks",
@@ -649,6 +650,7 @@
649650
DEVELOPMENT_TEAM = 29QXPN337R;
650651
ENABLE_BITCODE = NO;
651652
INFOPLIST_FILE = Runner/Info.plist;
653+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
652654
LD_RUNPATH_SEARCH_PATHS = (
653655
"$(inherited)",
654656
"@executable_path/Frameworks",
@@ -672,6 +674,7 @@
672674
DEVELOPMENT_TEAM = 29QXPN337R;
673675
ENABLE_BITCODE = NO;
674676
INFOPLIST_FILE = Runner/Info.plist;
677+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
675678
LD_RUNPATH_SEARCH_PATHS = (
676679
"$(inherited)",
677680
"@executable_path/Frameworks",

ios/Classes/SwiftFlutterDocumentScanSdkPlugin.swift

Lines changed: 100 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import DynamsoftCaptureVisionRouter
2-
3-
import DynamsoftCore
4-
5-
import DynamsoftDocumentNormalizer
6-
7-
import DynamsoftLicense
8-
9-
import DynamsoftUtility
1+
import DynamsoftCaptureVisionBundle
102

113
import Flutter
124

@@ -26,96 +18,101 @@ public class SwiftFlutterDocumentScanSdkPlugin: NSObject, FlutterPlugin, License
2618

2719
public func createNormalizedImage(_ result: CapturedResult) -> NSMutableDictionary {
2820
let dictionary = NSMutableDictionary()
29-
30-
if let item = result.items?.first, item.type == .normalizedImage {
31-
let imageItem : NormalizedImageResultItem = item as! NormalizedImageResultItem
32-
let imageData = imageItem.imageData
33-
let width = imageData!.width
34-
let height = imageData!.height
35-
let stride = imageData!.stride
36-
let format = imageData!.format
37-
let data = imageData!.bytes
38-
let length = data.count
39-
let orientation = imageData!.orientation
40-
41-
dictionary.setObject(width, forKey: "width" as NSCopying)
42-
dictionary.setObject(height, forKey: "height" as NSCopying)
43-
dictionary.setObject(stride, forKey: "stride" as NSCopying)
44-
dictionary.setObject(format.rawValue, forKey: "format" as NSCopying)
45-
dictionary.setObject(orientation, forKey: "orientation" as NSCopying)
46-
dictionary.setObject(length, forKey: "length" as NSCopying)
47-
48-
var rgba: [UInt8] = [UInt8](repeating: 0, count: Int(width * height) * 4)
49-
50-
if format == ImagePixelFormat.RGB888 {
51-
var dataIndex = 0
52-
for i in 0..<height {
53-
for j in 0..<width {
54-
let index = i * width + j
55-
rgba[Int(index) * 4] = data[dataIndex] // red
56-
rgba[Int(index) * 4 + 1] = data[dataIndex + 1] // green
57-
rgba[Int(index) * 4 + 2] = data[dataIndex + 2] // blue
58-
rgba[Int(index) * 4 + 3] = 255 // alpha
59-
dataIndex += 3
60-
}
61-
}
62-
} else if format == ImagePixelFormat.grayScaled || format == ImagePixelFormat.binaryInverted || format == ImagePixelFormat.binary8 {
63-
var dataIndex = 0
64-
for i in 0..<height {
65-
for j in 0..<width {
66-
let index = i * width + j
67-
rgba[Int(index) * 4] = data[dataIndex]
68-
rgba[Int(index) * 4 + 1] = data[dataIndex]
69-
rgba[Int(index) * 4 + 2] = data[dataIndex]
70-
rgba[Int(index) * 4 + 3] = 255
71-
dataIndex += 1
72-
}
73-
}
74-
} else if format == ImagePixelFormat.binary {
75-
var grayscale: [UInt8] = [UInt8](repeating: 0, count: Int(width * height))
76-
77-
var index = 0
78-
let skip = stride * 8 - width
79-
var shift = 0
80-
var n = 1
81-
82-
for i in 0..<length {
83-
let b = data[i]
84-
var byteCount = 7
85-
while byteCount >= 0 {
86-
let tmp = (b & (1 << byteCount)) >> byteCount
87-
88-
if shift < stride * 8 * UInt(n) - skip {
89-
if tmp == 1 {
90-
grayscale[index] = 255
91-
} else {
92-
grayscale[index] = 0
21+
22+
if let items = result.items {
23+
for item in items {
24+
if item.type == .enhancedImage {
25+
let imageItem : EnhancedImageResultItem = item as! EnhancedImageResultItem
26+
let imageData = imageItem.imageData
27+
let width = imageData!.width
28+
let height = imageData!.height
29+
let stride = imageData!.stride
30+
let format = imageData!.format
31+
let data = imageData!.bytes
32+
let length = data.count
33+
let orientation = imageData!.orientation
34+
35+
dictionary.setObject(width, forKey: "width" as NSCopying)
36+
dictionary.setObject(height, forKey: "height" as NSCopying)
37+
dictionary.setObject(stride, forKey: "stride" as NSCopying)
38+
dictionary.setObject(format.rawValue, forKey: "format" as NSCopying)
39+
dictionary.setObject(orientation, forKey: "orientation" as NSCopying)
40+
dictionary.setObject(length, forKey: "length" as NSCopying)
41+
42+
var rgba: [UInt8] = [UInt8](repeating: 0, count: Int(width * height) * 4)
43+
44+
if format == ImagePixelFormat.RGB888 {
45+
var dataIndex = 0
46+
for i in 0..<height {
47+
for j in 0..<width {
48+
let index = i * width + j
49+
rgba[Int(index) * 4] = data[dataIndex] // red
50+
rgba[Int(index) * 4 + 1] = data[dataIndex + 1] // green
51+
rgba[Int(index) * 4 + 2] = data[dataIndex + 2] // blue
52+
rgba[Int(index) * 4 + 3] = 255 // alpha
53+
dataIndex += 3
9354
}
94-
index += 1
9555
}
56+
} else if format == ImagePixelFormat.grayScaled || format == ImagePixelFormat.binaryInverted || format == ImagePixelFormat.binary8 {
57+
var dataIndex = 0
58+
for i in 0..<height {
59+
for j in 0..<width {
60+
let index = i * width + j
61+
rgba[Int(index) * 4] = data[dataIndex]
62+
rgba[Int(index) * 4 + 1] = data[dataIndex]
63+
rgba[Int(index) * 4 + 2] = data[dataIndex]
64+
rgba[Int(index) * 4 + 3] = 255
65+
dataIndex += 1
66+
}
67+
}
68+
} else if format == ImagePixelFormat.binary {
69+
var grayscale: [UInt8] = [UInt8](repeating: 0, count: Int(width * height))
70+
71+
var index = 0
72+
let skip = stride * 8 - width
73+
var shift = 0
74+
var n = 1
75+
76+
for i in 0..<length {
77+
let b = data[i]
78+
var byteCount = 7
79+
while byteCount >= 0 {
80+
let tmp = (b & (1 << byteCount)) >> byteCount
81+
82+
if shift < stride * 8 * UInt(n) - skip {
83+
if tmp == 1 {
84+
grayscale[index] = 255
85+
} else {
86+
grayscale[index] = 0
87+
}
88+
index += 1
89+
}
90+
91+
byteCount -= 1
92+
shift += 1
93+
}
9694

97-
byteCount -= 1
98-
shift += 1
99-
}
100-
101-
if shift == Int(stride) * 8 * n {
102-
n += 1
103-
}
104-
}
95+
if shift == Int(stride) * 8 * n {
96+
n += 1
97+
}
98+
}
10599

106-
var dataIndex = 0
107-
for i in 0..<height {
108-
for j in 0..<width {
109-
let index = i * width + j
110-
rgba[Int(index) * 4] = grayscale[dataIndex]
111-
rgba[Int(index) * 4 + 1] = grayscale[dataIndex]
112-
rgba[Int(index) * 4 + 2] = grayscale[dataIndex]
113-
rgba[Int(index) * 4 + 3] = 255
114-
dataIndex += 1
100+
var dataIndex = 0
101+
for i in 0..<height {
102+
for j in 0..<width {
103+
let index = i * width + j
104+
rgba[Int(index) * 4] = grayscale[dataIndex]
105+
rgba[Int(index) * 4 + 1] = grayscale[dataIndex]
106+
rgba[Int(index) * 4 + 2] = grayscale[dataIndex]
107+
rgba[Int(index) * 4 + 3] = 255
108+
dataIndex += 1
109+
}
110+
}
115111
}
112+
dictionary.setObject(rgba, forKey: "data" as NSCopying)
116113
}
114+
117115
}
118-
dictionary.setObject(rgba, forKey: "data" as NSCopying)
119116
}
120117

121118
return dictionary
@@ -161,7 +158,7 @@ public class SwiftFlutterDocumentScanSdkPlugin: NSObject, FlutterPlugin, License
161158
result(ret)
162159

163160
case "getParameters":
164-
result(try? cvr.outputSettings(""))
161+
result(try? cvr.outputSettings("", includeDefaultValues: false))
165162
case "detectFile":
166163
let arguments: NSDictionary = call.arguments as! NSDictionary
167164
DispatchQueue.global().async {
@@ -226,10 +223,12 @@ public class SwiftFlutterDocumentScanSdkPlugin: NSObject, FlutterPlugin, License
226223
imageData.orientation = rotation
227224

228225
let points = [
229-
CGPoint(x: x1, y: y1), CGPoint(x: x2, y: y2), CGPoint(x: x3, y: y3),
230-
CGPoint(x: x4, y: y4),
226+
CGPoint(x: x1, y: y1), CGPoint(x: x2, y: y2),
227+
CGPoint(x: x3, y: y3), CGPoint(x: x4, y: y4)
231228
]
232-
let quad = Quadrilateral.init(pointArray: points)
229+
230+
let nsPoints = points.map { NSValue(cgPoint: $0) }
231+
let quad = Quadrilateral(pointArray: nsPoints)
233232

234233
var mode = ImageColourMode.colour
235234

@@ -268,11 +267,13 @@ public class SwiftFlutterDocumentScanSdkPlugin: NSObject, FlutterPlugin, License
268267
let colorMode: Int = arguments.value(forKey: "color") as! Int
269268

270269
let points = [
271-
CGPoint(x: x1, y: y1), CGPoint(x: x2, y: y2), CGPoint(x: x3, y: y3),
272-
CGPoint(x: x4, y: y4),
270+
CGPoint(x: x1, y: y1), CGPoint(x: x2, y: y2),
271+
CGPoint(x: x3, y: y3), CGPoint(x: x4, y: y4)
273272
]
274-
let quad = Quadrilateral.init(pointArray: points)
275273

274+
let nsPoints = points.map { NSValue(cgPoint: $0) }
275+
let quad = Quadrilateral(pointArray: nsPoints)
276+
276277
var mode = ImageColourMode.colour
277278

278279
switch colorMode {

ios/flutter_document_scan_sdk.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A Flutter wrapper for Dynamsoft Document Normalizer, providing API for document
1616
s.source_files = 'Classes/**/*'
1717
s.dependency 'Flutter'
1818
s.platform = :ios, '9.0'
19-
s.dependency 'DynamsoftCaptureVisionBundle', '2.6.1004'
19+
s.dependency 'DynamsoftCaptureVisionBundle', '3.0.3000'
2020
# Flutter.framework does not contain a i386 slice.
2121
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
2222
s.swift_version = '5.0'

0 commit comments

Comments
 (0)