55
66@interface BarcodeDetectorManagerMlkit ()
77@property (nonatomic , strong ) MLKBarcodeScanner *barcodeRecognizer;
8- @property (nonatomic , strong ) FIRVision *vision;
9- @property (nonatomic , assign ) FIRVisionBarcodeFormat setOption;
8+ @property (nonatomic , strong ) MLK *vision;
9+ @property (nonatomic , assign ) MLKBarcodeFormat setOption;
1010@property (nonatomic , assign ) NSInteger detectionMode;
1111@property (nonatomic , assign ) float scaleX;
1212@property (nonatomic , assign ) float scaleY;
@@ -17,7 +17,7 @@ @implementation BarcodeDetectorManagerMlkit
1717- (instancetype )init
1818{
1919 if (self = [super init ]) {
20- self.vision = [FIRVision vision ];
20+ self.vision = [MLK vision ];
2121 self.barcodeRecognizer = [_vision barcodeDetector ];
2222 }
2323 return self;
@@ -36,20 +36,20 @@ -(NSInteger)fetchDetectionMode
3636+ (NSDictionary *)constants
3737{
3838 return @{
39- @" CODE_128" : @(FIRVisionBarcodeFormatCode128 ),
40- @" CODE_39" : @(FIRVisionBarcodeFormatCode39 ),
41- @" CODE_93" : @(FIRVisionBarcodeFormatCode93 ),
42- @" CODABAR" : @(FIRVisionBarcodeFormatCodaBar ),
43- @" EAN_13" : @(FIRVisionBarcodeFormatEAN13 ),
44- @" EAN_8" : @(FIRVisionBarcodeFormatEAN8 ),
45- @" ITF" : @(FIRVisionBarcodeFormatITF ),
46- @" UPC_A" : @(FIRVisionBarcodeFormatUPCA ),
47- @" UPC_E" : @(FIRVisionBarcodeFormatUPCE ),
48- @" QR_CODE" : @(FIRVisionBarcodeFormatQRCode ),
49- @" PDF417" : @(FIRVisionBarcodeFormatPDF417 ),
50- @" AZTEC" : @(FIRVisionBarcodeFormatAztec ),
51- @" DATA_MATRIX" : @(FIRVisionBarcodeFormatDataMatrix ),
52- @" ALL" : @(FIRVisionBarcodeFormatAll ),
39+ @" CODE_128" : @(MLKBarcodeFormatCode128 ),
40+ @" CODE_39" : @(MLKBarcodeFormatCode39 ),
41+ @" CODE_93" : @(MLKBarcodeFormatCode93 ),
42+ @" CODABAR" : @(MLKBarcodeFormatCodaBar ),
43+ @" EAN_13" : @(MLKBarcodeFormatEAN13 ),
44+ @" EAN_8" : @(MLKBarcodeFormatEAN8 ),
45+ @" ITF" : @(MLKBarcodeFormatITF ),
46+ @" UPC_A" : @(MLKBarcodeFormatUPCA ),
47+ @" UPC_E" : @(MLKBarcodeFormatUPCE ),
48+ @" QR_CODE" : @(MLKBarcodeFormatQRCode ),
49+ @" PDF417" : @(MLKBarcodeFormatPDF417 ),
50+ @" AZTEC" : @(MLKBarcodeFormatAztec ),
51+ @" DATA_MATRIX" : @(MLKBarcodeFormatDataMatrix ),
52+ @" ALL" : @(MLKBarcodeFormatAll ),
5353 };
5454}
5555
@@ -86,7 +86,7 @@ - (void)findBarcodesInFrame:(UIImage *)uiImage
8686 MLKVisionImage *image = [[MLKVisionImage alloc ] initWithImage: uiImage];
8787 NSMutableArray *emptyResult = [[NSMutableArray alloc ] init ];
8888 [_barcodeRecognizer detectInImage: image
89- completion: ^(NSArray <FIRVisionBarcode *> *barcodes, NSError *error) {
89+ completion: ^(NSArray <MLKBarcode *> *barcodes, NSError *error) {
9090 if (error != nil || barcodes == nil ) {
9191 completed (emptyResult);
9292 } else {
@@ -98,7 +98,7 @@ - (void)findBarcodesInFrame:(UIImage *)uiImage
9898- (NSArray *)processBarcodes : (NSArray *)barcodes imageContainingBarcodes : (UIImage *)imageContainingBarcodes
9999{
100100 NSMutableArray *result = [[NSMutableArray alloc ] init ];
101- for (FIRVisionBarcode *barcode in barcodes) {
101+ for (MLKBarcode *barcode in barcodes) {
102102 NSMutableDictionary *resultDict =
103103 [[NSMutableDictionary alloc ] initWithCapacity: 20 ];
104104 // Boundaries of a barcode in image
@@ -118,24 +118,24 @@ - (NSArray *)processBarcodes:(NSArray *)barcodes imageContainingBarcodes:(UIImag
118118 [UIImageJPEGRepresentation (imageContainingBarcodes, 1.0 ) writeToFile: path atomically: YES ];
119119 [resultDict setObject: path forKey: @" uri" ];
120120
121- FIRVisionBarcodeValueType valueType = barcode.valueType ;
121+ MLKBarcodeValueType valueType = barcode.valueType ;
122122 [resultDict setObject: [self getType: barcode.valueType] forKey: @" type" ];
123123
124124 switch (valueType) {
125- case FIRVisionBarcodeValueTypeWiFi :
125+ case MLKBarcodeValueTypeWiFi :
126126 if (barcode.wifi .ssid ) {[resultDict setObject: barcode.wifi.ssid forKey: @" ssid" ]; }
127127 if (barcode.wifi .password ) {[resultDict setObject: barcode.wifi.password forKey: @" password" ]; }
128128 if (barcode.wifi .type ) {
129129 NSString *encryptionTypeString = @" UNKNOWN" ;
130130 int type = barcode.wifi .type ;
131131 switch (type) {
132- case FIRVisionBarcodeWiFiEncryptionTypeWEP :
132+ case MLKBarcodeWiFiEncryptionTypeWEP :
133133 encryptionTypeString = @" WEP" ;
134134 break ;
135- case FIRVisionBarcodeWiFiEncryptionTypeWPA :
135+ case MLKBarcodeWiFiEncryptionTypeWPA :
136136 encryptionTypeString = @" WPA" ;
137137 break ;
138- case FIRVisionBarcodeWiFiEncryptionTypeOpen :
138+ case MLKBarcodeWiFiEncryptionTypeOpen :
139139 encryptionTypeString = @" Open" ;
140140 break ;
141141 default :
@@ -144,27 +144,27 @@ - (NSArray *)processBarcodes:(NSArray *)barcodes imageContainingBarcodes:(UIImag
144144 [resultDict setObject: encryptionTypeString forKey: @" encryptionType" ];
145145 }
146146 break ;
147- case FIRVisionBarcodeValueTypeURL :
147+ case MLKBarcodeValueTypeURL :
148148 if (barcode.URL .url ) { [resultDict setObject: barcode.URL .url forKey: @" url" ]; }
149149 if (barcode.URL .title ) { [resultDict setObject: barcode.URL .title forKey: @" title" ]; }
150150 break ;
151- case FIRVisionBarcodeValueTypeContactInfo :
151+ case MLKBarcodeValueTypeContactInfo :
152152 if (barcode.contactInfo .addresses ) {
153153 NSMutableArray *addresses = [[NSMutableArray alloc ] init ];
154- for (FIRVisionBarcodeAddress *address in barcode.contactInfo .addresses ) {
154+ for (MLKBarcodeAddress *address in barcode.contactInfo .addresses ) {
155155 [addresses addObject: [self processAddress: address]];
156156 }
157157 [resultDict setObject: addresses forKey: @" addresses" ];
158158 }
159159 if (barcode.contactInfo .emails ) {
160160 NSMutableArray *emails = [[NSMutableArray alloc ] init ];
161- for (FIRVisionBarcodeEmail *email in barcode.contactInfo .emails ) {
161+ for (MLKBarcodeEmail *email in barcode.contactInfo .emails ) {
162162 [emails addObject: [self processEmail: email]];
163163 }
164164 [resultDict setObject: emails forKey: @" emails" ];
165165 }
166166 if (barcode.contactInfo .name ) {
167- FIRVisionBarcodePersonName *name = barcode.contactInfo .name ;
167+ MLKBarcodePersonName *name = barcode.contactInfo .name ;
168168 NSObject *nameObject = @{
169169 @" formattedName" : name.formattedName ? name.formattedName : @" " ,
170170 @" firstName" : name.first ? name.first : @" " ,
@@ -178,23 +178,23 @@ - (NSArray *)processBarcodes:(NSArray *)barcodes imageContainingBarcodes:(UIImag
178178 }
179179 if (barcode.contactInfo .phones ) {
180180 NSMutableArray *phones = [[NSMutableArray alloc ] init ];
181- for (FIRVisionBarcodePhone *phone in barcode.contactInfo .phones ) {
181+ for (MLKBarcodePhone *phone in barcode.contactInfo .phones ) {
182182 [phones addObject: [self processPhone: phone]];
183183 }
184184 [resultDict setObject: phones forKey: @" phones" ];
185185 }
186186 if (barcode.contactInfo .urls ) {[resultDict setObject: barcode.contactInfo.urls forKey: @" urls" ]; }
187187 if (barcode.contactInfo .organization ) {[resultDict setObject: barcode.contactInfo.organization forKey: @" organization" ]; }
188188 break ;
189- case FIRVisionBarcodeValueTypeSMS :
189+ case MLKBarcodeValueTypeSMS :
190190 if (barcode.sms .message ) {[resultDict setObject: barcode.sms.message forKey: @" message" ]; }
191191 if (barcode.sms .phoneNumber ) {[resultDict setObject: barcode.sms.phoneNumber forKey: @" phoneNumber" ]; }
192192 break ;
193- case FIRVisionBarcodeValueTypeGeographicCoordinates :
193+ case MLKBarcodeValueTypeGeographicCoordinates :
194194 if (barcode.geoPoint .latitude ) {[resultDict setObject: @(barcode.geoPoint.latitude) forKey: @" latitude" ]; }
195195 if (barcode.geoPoint .longitude ) {[resultDict setObject: @(barcode.geoPoint.longitude) forKey: @" longitude" ]; }
196196 break ;
197- case FIRVisionBarcodeValueTypeDriversLicense :
197+ case MLKBarcodeValueTypeDriversLicense :
198198 if (barcode.driverLicense .firstName ) {[resultDict setObject: barcode.driverLicense.firstName forKey: @" firstName" ]; }
199199 if (barcode.driverLicense .middleName ) {[resultDict setObject: barcode.driverLicense.middleName forKey: @" middleName" ]; }
200200 if (barcode.driverLicense .lastName ) {[resultDict setObject: barcode.driverLicense.lastName forKey: @" lastName" ]; }
@@ -210,7 +210,7 @@ - (NSArray *)processBarcodes:(NSArray *)barcodes imageContainingBarcodes:(UIImag
210210 if (barcode.driverLicense .issuingDate ) {[resultDict setObject: barcode.driverLicense.issuingDate forKey: @" issuingDate" ]; }
211211 if (barcode.driverLicense .issuingCountry ) {[resultDict setObject: barcode.driverLicense.issuingCountry forKey: @" issuingCountry" ]; }
212212 break ;
213- case FIRVisionBarcodeValueTypeCalendarEvent :
213+ case MLKBarcodeValueTypeCalendarEvent :
214214 if (barcode.calendarEvent .eventDescription ) {[resultDict setObject: barcode.calendarEvent.eventDescription forKey: @" eventDescription" ]; }
215215 if (barcode.calendarEvent .location ) {[resultDict setObject: barcode.calendarEvent.location forKey: @" location" ]; }
216216 if (barcode.calendarEvent .organizer ) {[resultDict setObject: barcode.calendarEvent.organizer forKey: @" organizer" ]; }
@@ -223,13 +223,13 @@ - (NSArray *)processBarcodes:(NSArray *)barcodes imageContainingBarcodes:(UIImag
223223 [resultDict setObject: [self processDate: barcode.calendarEvent.end] forKey: @" end" ];
224224 }
225225 break ;
226- case FIRVisionBarcodeValueTypePhone :
226+ case MLKBarcodeValueTypePhone :
227227 if (barcode.phone .number ) {[resultDict setObject: barcode.phone.number forKey: @" number" ]; }
228228 if (barcode.phone .type ) {
229229 [resultDict setObject: [self getPhoneType: barcode.phone.type] forKey: @" phoneType" ];
230230 }
231231 break ;
232- case FIRVisionBarcodeValueTypeEmail :
232+ case MLKBarcodeValueTypeEmail :
233233 if (barcode.email .address ) {[resultDict setObject: barcode.email.address forKey: @" address" ]; }
234234 if (barcode.email .body ) {[resultDict setObject: barcode.email.body forKey: @" body" ]; }
235235 if (barcode.email .subject ) {[resultDict setObject: barcode.email.subject forKey: @" subject" ]; }
@@ -247,37 +247,37 @@ - (NSString *)getType:(int)type
247247{
248248 NSString *barcodeType = @" UNKNOWN" ;
249249 switch (type) {
250- case FIRVisionBarcodeValueTypeEmail :
250+ case MLKBarcodeValueTypeEmail :
251251 barcodeType = @" EMAIL" ;
252252 break ;
253- case FIRVisionBarcodeValueTypePhone :
253+ case MLKBarcodeValueTypePhone :
254254 barcodeType = @" PHONE" ;
255255 break ;
256- case FIRVisionBarcodeValueTypeCalendarEvent :
256+ case MLKBarcodeValueTypeCalendarEvent :
257257 barcodeType = @" CALENDAR_EVENT" ;
258258 break ;
259- case FIRVisionBarcodeValueTypeDriversLicense :
259+ case MLKBarcodeValueTypeDriversLicense :
260260 barcodeType = @" DRIVER_LICENSE" ;
261261 break ;
262- case FIRVisionBarcodeValueTypeGeographicCoordinates :
262+ case MLKBarcodeValueTypeGeographicCoordinates :
263263 barcodeType = @" GEO" ;
264264 break ;
265- case FIRVisionBarcodeValueTypeSMS :
265+ case MLKBarcodeValueTypeSMS :
266266 barcodeType = @" SMS" ;
267267 break ;
268- case FIRVisionBarcodeValueTypeContactInfo :
268+ case MLKBarcodeValueTypeContactInfo :
269269 barcodeType = @" CONTACT_INFO" ;
270270 break ;
271- case FIRVisionBarcodeValueTypeWiFi :
271+ case MLKBarcodeValueTypeWiFi :
272272 barcodeType = @" WIFI" ;
273273 break ;
274- case FIRVisionBarcodeValueTypeText :
274+ case MLKBarcodeValueTypeText :
275275 barcodeType = @" TEXT" ;
276276 break ;
277- case FIRVisionBarcodeValueTypeISBN :
277+ case MLKBarcodeValueTypeISBN :
278278 barcodeType = @" ISBN" ;
279279 break ;
280- case FIRVisionBarcodeValueTypeProduct :
280+ case MLKBarcodeValueTypeProduct :
281281 barcodeType = @" PRODUCT" ;
282282 break ;
283283 default :
@@ -290,14 +290,14 @@ - (NSString *)getPhoneType:(int)type
290290{
291291 NSString *typeString = @" UNKNOWN" ;
292292 switch (type) {
293- case FIRVisionBarcodePhoneTypeFax :
293+ case MLKBarcodePhoneTypeFax :
294294 typeString = @" Fax" ;
295295 break ;
296- case FIRVisionBarcodePhoneTypeHome :
296+ case MLKBarcodePhoneTypeHome :
297297 typeString = @" Home" ;
298- case FIRVisionBarcodePhoneTypeWork :
298+ case MLKBarcodePhoneTypeWork :
299299 typeString = @" Work" ;
300- case FIRVisionBarcodePhoneTypeMobile :
300+ case MLKBarcodePhoneTypeMobile :
301301 typeString = @" Mobile" ;
302302 default :
303303 break ;
@@ -309,18 +309,18 @@ - (NSString *)getEmailType:(int)type
309309{
310310 NSString *typeString = @" UNKNOWN" ;
311311 switch (type) {
312- case FIRVisionBarcodeEmailTypeWork :
312+ case MLKBarcodeEmailTypeWork :
313313 typeString = @" Work" ;
314314 break ;
315- case FIRVisionBarcodeEmailTypeHome :
315+ case MLKBarcodeEmailTypeHome :
316316 typeString = @" Home" ;
317317 default :
318318 break ;
319319 }
320320 return typeString;
321321}
322322
323- - (NSDictionary *)processPhone : (FIRVisionBarcodePhone *)phone
323+ - (NSDictionary *)processPhone : (MLKBarcodePhone *)phone
324324{
325325 NSString *number = @" " ;
326326 NSString *typeString = @" UNKNOWN" ;
@@ -331,18 +331,18 @@ - (NSDictionary *)processPhone:(FIRVisionBarcodePhone *)phone
331331 return @{@" number" : number, @" phoneType" : typeString};
332332}
333333
334- - (NSDictionary *)processAddress : (FIRVisionBarcodeAddress *)address
334+ - (NSDictionary *)processAddress : (MLKBarcodeAddress *)address
335335{
336336 NSArray *addressLines = [[NSArray alloc ] init ];
337337 NSString *typeString = @" UNKNOWN" ;
338338 if (address) {
339339 int type = address.type ;
340340 NSString *typeString = @" UNKNOWN" ;
341341 switch (type) {
342- case FIRVisionBarcodeAddressTypeWork :
342+ case MLKBarcodeAddressTypeWork :
343343 typeString = @" Work" ;
344344 break ;
345- case FIRVisionBarcodeAddressTypeHome :
345+ case MLKBarcodeAddressTypeHome :
346346 typeString = @" Home" ;
347347 default :
348348 break ;
@@ -352,7 +352,7 @@ - (NSDictionary *)processAddress:(FIRVisionBarcodeAddress *)address
352352 return @{@" addressLines" : addressLines, @" addressType" : typeString};
353353}
354354
355- - (NSDictionary *)processEmail : (FIRVisionBarcodeEmail *)email
355+ - (NSDictionary *)processEmail : (MLKBarcodeEmail *)email
356356{
357357 NSString *subject = @" " ;
358358 NSString *address =@" " ;
@@ -388,7 +388,7 @@ - (NSDictionary *)processBounds:(CGRect)bounds
388388}
389389
390390
391- - (NSDictionary *)processPoint : (FIRVisionPoint *)point
391+ - (NSDictionary *)processPoint : (MLKPoint *)point
392392{
393393 float originX = [point.x floatValue ] * _scaleX;
394394 float originY = [point.y floatValue ] * _scaleY;
0 commit comments