This topic describes how to use the multi-code recognition feature of the scan SDK in the custom baseline cp_change_28238
or baseline version 10.2.3.5 or later. You can integrate multi-code recognition SDK to iOS client based on native project with CocoaPods.
Prerequisites
You have connected your project to mPaaS. For more information, see Access based on native framework and using Cocoapods.
Add the SDK
Use CocoaPods plugin to add the multi-code recognition SDK. Complete the following steps:
Open the
Podfile
file, change mPaaS_baseline tocp_change_28238
or baseline version 10.2.3.5 or later.Run
mPaaS_pod "mPaaS_ScanCode"
to add dependencies for the scan component.Click here to learn how to use CocoaPods. In the CLI, run
pod install
orpod update
to add the SDK.
Use the SDK
This section describes how to use the multi-code recognition feature of the scan SDK in the customized baseline cp_change_28238
or baseline version 10.2.3.5 or later. The official demo of the scan component is used for reference.
Open the default scan page
The multi-code recognition feature is available only in a standard UI.
Trigger the default scan page and process the scan results.
#import <TBScanSDK/TBScanSDK.h> @interface MPScanDemoVC() @property(nonatomic, strong) TBScanViewController *scanVC; @end - (void)defaultScan { // Define whether to display the entry to the album. [MPScanCodeAdapterInterface sharedInstance].shoulShowAlbum = NO; TBScanViewController *vc = [[MPScanCodeAdapterInterface sharedInstance] createDefaultScanPageWithallback:^(id _Nonnull result, BOOL keepAlive) { // Process the scan results. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:result[@"resp_result"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; alert.tag = 1999; [alert show]; }]; // Set the type of the scan. vc.scanType = ScanType_Default_Code; [self.navigationController pushViewController:vc animated:YES]; self.scanVC = vc; }
Perform multi-code recognition and continuous code scan.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // Enable continuous code scan. [self.scanVC resumeCaptureSession]; }
How to use the custom UI
This article will introduce how to use the multi-code recognition feature SDK under the custom UI in conjunction with the scan official demo.
Customize the ViewController that inherits TBScanViewController
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface MPScanCodeViewController : TBScanViewController<TBScanViewControllerDelegate>
@end
NS_ASSUME_NONNULL_END
Initialize custom scan ViewController
//Custom scan entrance
- (void)customScanAction
{
MPScanCodeViewController *vc = [[MPScanCodeViewController alloc] initWithConfig:@{}];
[self.navigationController pushViewController:vc animated:YES];
}
@implementation MPScanCodeViewController
- (instancetype)initWithConfig:(NSDictionary *)config
{
if (self = [super initWithConfig:config])
{
self.delegate = self;
self.scanType = ScanType_All_Code;
}
return self;
}
The ViewController that initializes the custom scan code can only use the -(instancetype)initWithConfig:(NSDictionary *)config;
method.
Customize the scan box
- (void)buildContainerView:(UIView*)containerView
{
// Customize the scan box view
UIView* bg = [[UIView alloc] initWithFrame:containerView.bounds];
[containerView addSubview:bg];
CGRect rect = [MPScanCodeViewController constructScanAnimationRect];
UIView* view = [[UIView alloc] initWithFrame:rect];
view.backgroundColor = [UIColor orangeColor];
view.alpha = 0.5;
[bg addSubview:view];
}
Handle scan results
Users handle it according to their own business scenarios.
#pragma mark TBScanViewControllerDelegate
-(void)didFind:(NSArray<TBScanResult*>*)resultArray
{
TBScanResult *result = resultArray.firstObject;
NSString* content = result.data;
if (result.resultType == TBScanResultTypeQRCode) {
content = [NSString stringWithFormat:@"qrcode:%@, hiddenData:%@, TBScanQRCodeResultType:%@", result.data, result.hiddenData, [result.extData objectForKey:TBScanResultTypeQRCode]];
NSLog(@"subType is %@, ScanType_QRCode is %@", @(result.subType), @(ScanType_QRCode));
} else if (result.resultType == TBScanResultTypeVLGen3Code) {
content = [NSString stringWithFormat:@"gen3:%@", result.data];
NSLog(@"subType is %@, ScanType_GEN3 is %@", @(result.subType), @(ScanType_GEN3));
} else if (result.resultType == TBScanResultTypeGoodsBarcode) {
content = [NSString stringWithFormat:@"barcode:%@", result.data];
NSLog(@"subType is %@, EAN13 is %@", @(result.subType), @(EAN13));
} else if (result.resultType == TBScanResultTypeDataMatrixCode) {
content = [NSString stringWithFormat:@"dm:%@", result.data];
NSLog(@"subType is %@, ScanType_DATAMATRIX is %@", @(result.subType), @(ScanType_DATAMATRIX));
} else if (result.resultType == TBScanResultTypeExpressCode) {
content = [NSString stringWithFormat:@"express:%@", result.data];
NSLog(@"subType is %@, ScanType_FASTMAIL is %@", @(result.subType), @(ScanType_FASTMAIL));
}
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:content delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
alert.tag = 9999;
[alert show];
});
}