Skip to content

Commit 2f4ad8f

Browse files
authored
ios: expose all native result items in wrapper (#649)
So ecLevel and all the other fields can be accessed from iOS apps too.
1 parent 829910b commit 2f4ad8f

File tree

7 files changed

+111
-10
lines changed

7 files changed

+111
-10
lines changed

wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@
66
#import "ReadBarcode.h"
77
#import "ImageView.h"
88
#import "Result.h"
9+
#import "GTIN.h"
910
#import "ZXIFormatHelper.h"
1011
#import "ZXIPosition+Helper.h"
1112

1213
using namespace ZXing;
1314

15+
NSString *stringToNSString(const std::string &text) {
16+
return [[NSString alloc]initWithBytes:text.data() length:text.size() encoding:NSUTF8StringEncoding];
17+
}
18+
19+
ZXIGTIN *getGTIN(const Result &result) {
20+
auto country = GTIN::LookupCountryIdentifier(result.text(TextMode::Plain), result.format());
21+
auto addOn = GTIN::EanAddOn(result);
22+
return country.empty()
23+
? nullptr
24+
: [[ZXIGTIN alloc]initWithCountry:stringToNSString(country)
25+
addOn:stringToNSString(addOn)
26+
price:stringToNSString(GTIN::Price(addOn))
27+
issueNumber:stringToNSString(GTIN::IssueNr(addOn))];
28+
}
29+
1430
@interface ZXIBarcodeReader()
1531
@property (nonatomic, strong) CIContext* ciContext;
1632
@end
@@ -115,16 +131,21 @@ + (DecodeHints)DecodeHintsFromZXIOptions:(ZXIDecodeHints*)hints {
115131

116132
NSMutableArray* zxiResults = [NSMutableArray array];
117133
for (auto result: results) {
118-
auto resultText = result.text();
119-
NSString *text = [[NSString alloc]initWithBytes:resultText.data() length:resultText.size() encoding:NSUTF8StringEncoding];
120-
121-
NSData *bytes = [[NSData alloc] initWithBytes:result.bytes().data() length:result.bytes().size()];
122134
[zxiResults addObject:
123-
[[ZXIResult alloc] init:text
135+
[[ZXIResult alloc] init:stringToNSString(result.text())
124136
format:ZXIFormatFromBarcodeFormat(result.format())
125-
bytes:bytes
137+
bytes:[[NSData alloc] initWithBytes:result.bytes().data() length:result.bytes().size()]
126138
position:[[ZXIPosition alloc]initWithPosition: result.position()]
127-
]];
139+
orientation:result.orientation()
140+
ecLevel:stringToNSString(result.ecLevel())
141+
symbologyIdentifier:stringToNSString(result.symbologyIdentifier())
142+
sequenceSize:result.sequenceSize()
143+
sequenceIndex:result.sequenceIndex()
144+
sequenceId:stringToNSString(result.sequenceId())
145+
readerInit:result.readerInit()
146+
lineCount:result.lineCount()
147+
gtin:getGTIN(result)]
148+
];
128149
}
129150
return zxiResults;
130151
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2022 KURZ Digital Solutions GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
6+
#import <Foundation/Foundation.h>
7+
8+
NS_ASSUME_NONNULL_BEGIN
9+
10+
@interface ZXIGTIN : NSObject
11+
@property(nonatomic, nonnull)NSString *country;
12+
@property(nonatomic, nonnull)NSString *addOn;
13+
@property(nonatomic, nonnull)NSString *price;
14+
@property(nonatomic, nonnull)NSString *issueNumber;
15+
16+
- (instancetype)initWithCountry:(NSString *)country
17+
addOn:(NSString *)addOn
18+
price:(NSString *)price
19+
issueNumber:(NSString *)issueNumber;
20+
@end
21+
22+
NS_ASSUME_NONNULL_END
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2022 KURZ Digital Solutions GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
6+
#import "ZXIGTIN.h"
7+
8+
@implementation ZXIGTIN
9+
- (instancetype)initWithCountry:(NSString *)country
10+
addOn:(NSString *)addOn
11+
price:(NSString *)price
12+
issueNumber:(NSString *)issueNumber {
13+
self = [super init];
14+
self.country = country;
15+
self.addOn = addOn;
16+
self.price = price;
17+
self.issueNumber = issueNumber;
18+
return self;
19+
}
20+
@end

wrappers/ios/Sources/Wrapper/Reader/ZXIResult.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#import <Foundation/Foundation.h>
66
#import "ZXIFormat.h"
77
#import "ZXIPosition.h"
8+
#import "ZXIGTIN.h"
89

910
NS_ASSUME_NONNULL_BEGIN
1011

@@ -13,11 +14,29 @@ NS_ASSUME_NONNULL_BEGIN
1314
@property(nonatomic, strong) NSData *bytes;
1415
@property(nonatomic, strong) ZXIPosition *position;
1516
@property(nonatomic) ZXIFormat format;
17+
@property(nonatomic) NSInteger orientation;
18+
@property(nonatomic, strong) NSString *ecLevel;
19+
@property(nonatomic, strong) NSString *symbologyIdentifier;
20+
@property(nonatomic) NSInteger sequenceSize;
21+
@property(nonatomic) NSInteger sequenceIndex;
22+
@property(nonatomic, strong) NSString *sequenceId;
23+
@property(nonatomic) BOOL readerInit;
24+
@property(nonatomic) NSInteger lineCount;
25+
@property(nonatomic, strong) ZXIGTIN *gtin;
1626

1727
- (instancetype)init:(NSString *)text
1828
format:(ZXIFormat)format
1929
bytes:(NSData *)bytes
20-
position:(ZXIPosition *)position;
30+
position:(ZXIPosition *)position
31+
orientation:(NSInteger)orientation
32+
ecLevel:(NSString *)ecLevel
33+
symbologyIdentifier:(NSString *)symbologyIdentifier
34+
sequenceSize:(NSInteger)sequenceSize
35+
sequenceIndex:(NSInteger)sequenceIndex
36+
sequenceId:(NSString *)sequenceId
37+
readerInit:(BOOL)readerInit
38+
lineCount:(NSInteger)lineCount
39+
gtin:(ZXIGTIN *)gtin;
2140
@end
2241

2342
NS_ASSUME_NONNULL_END

wrappers/ios/Sources/Wrapper/Reader/ZXIResult.mm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,30 @@ @implementation ZXIResult
88
- (instancetype)init:(NSString *)text
99
format:(ZXIFormat)format
1010
bytes:(NSData *)bytes
11-
position:(ZXIPosition *)position {
11+
position:(ZXIPosition *)position
12+
orientation:(NSInteger)orientation
13+
ecLevel:(NSString *)ecLevel
14+
symbologyIdentifier:(NSString *)symbologyIdentifier
15+
sequenceSize:(NSInteger)sequenceSize
16+
sequenceIndex:(NSInteger)sequenceIndex
17+
sequenceId:(NSString *)sequenceId
18+
readerInit:(BOOL)readerInit
19+
lineCount:(NSInteger)lineCount
20+
gtin:(ZXIGTIN *)gtin {
1221
self = [super init];
1322
self.text = text;
1423
self.format = format;
1524
self.bytes = bytes;
1625
self.position = position;
26+
self.orientation = orientation;
27+
self.ecLevel = ecLevel;
28+
self.symbologyIdentifier = symbologyIdentifier;
29+
self.sequenceSize = sequenceSize;
30+
self.sequenceIndex = sequenceIndex;
31+
self.sequenceId = sequenceId;
32+
self.readerInit = readerInit;
33+
self.lineCount = lineCount;
34+
self.gtin = gtin;
1735
return self;
1836
}
1937
@end

wrappers/ios/Sources/Wrapper/UmbrellaHeader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "Reader/ZXIResult.h"
1010
#import "Reader/ZXIPosition.h"
1111
#import "Reader/ZXIPoint.h"
12+
#import "Reader/ZXIGTIN.h"
1213
#import "Reader/ZXIDecodeHints.h"
1314
#import "Writer/ZXIEncodeHints.h"
1415
#import "Writer/ZXIBarcodeWriter.h"

zxing-cpp.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Pod::Spec.new do |s|
3131
ss.dependency 'zxing-cpp/Core'
3232
ss.frameworks = 'CoreGraphics', 'CoreImage', 'CoreVideo'
3333
ss.source_files = 'wrappers/ios/Sources/Wrapper/**/*.{h,m,mm}'
34-
ss.public_header_files = 'wrappers/ios/Sources/Wrapper/Reader/{ZXIBarcodeReader,ZXIResult,ZXIPosition,ZXIPoint,ZXIDecodeHints}.h',
34+
ss.public_header_files = 'wrappers/ios/Sources/Wrapper/Reader/{ZXIBarcodeReader,ZXIResult,ZXIPosition,ZXIPoint,ZXIGTIN,ZXIDecodeHints}.h',
3535
'wrappers/ios/Sources/Wrapper/Writer/{ZXIBarcodeWriter,ZXIEncodeHints}.h',
3636
'wrappers/ios/Sources/Wrapper/{ZXIErrors,ZXIFormat}.h'
3737
ss.exclude_files = 'wrappers/ios/Sources/Wrapper/UmbrellaHeader.h'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy