Este tema describe cómo utilizar el SDK de reconocimiento multicódigo de Scan con la línea base personalizada cp_change_28238 o la línea base 10.2.3.5 y versiones posteriores. Puede integrar el SDK de reconocimiento multicódigo en un cliente iOS a partir de un proyecto existente mediante CocoaPods.
Requisitos previos
Debe haber conectado su proyecto a mPaaS. Para obtener más información, consulte Based on an existing project using CocoaPods.
Agregar el SDK
Utilice el plugin cocoapods-mPaaS para agregar el SDK de reconocimiento multicódigo. El procedimiento es el siguiente:
En el archivo
Podfile, cambie mPaaS_baseline acp_change_28238o a la línea base 10.2.3.5 o posterior.-
Utilice
mPaaS_pod "mPaaS_ScanCode"para agregar la dependencia del componente Scan.
Consulte Click here para aprender a usar CocoaPods. Luego, ejecute
pod installopod updateen la línea de comandos según sea necesario para completar la integración.
Usar el SDK
Abrir la página de escaneo predeterminada
Esta sección utiliza la demostración oficial Scan para describir cómo usar el SDK de reconocimiento multicódigo de Scan con la interfaz de usuario predeterminada en la línea base personalizada cp_change_28238 o la línea base 10.2.3.5 y versiones posteriores.
-
Abra la página de escaneo predeterminada y procese los resultados del escaneo.
#import <TBScanSDK/TBScanSDK.h> @interface MPScanDemoVC() @property(nonatomic, strong) TBScanViewController *scanVC; @end - (void)defaultScan { // Specifies whether to show the album entry. [MPScanCodeAdapterInterface sharedInstance].shoulShowAlbum = NO; TBScanViewController *vc = [[MPScanCodeAdapterInterface sharedInstance] createDefaultScanPageWithallback:^(id _Nonnull result, BOOL keepAlive) { // Process the scan result. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:result[@"resp_result"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; alert.tag = 1999; [alert show]; }]; // Set the scan type. vc.scanType = ScanType_Default_Code; [self.navigationController pushViewController:vc animated:YES]; self.scanVC = vc; } -
Para el reconocimiento multicódigo, habilite el escaneo continuo.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // Continue scanning. [self.scanVC resumeCaptureSession]; }
Cómo usar la interfaz de usuario personalizada
Esta sección utiliza la demostración oficial de Scan para describir cómo usar el SDK de reconocimiento multicódigo de Scan con una interfaz de usuario personalizada.
Crear un ViewController personalizado que herede de TBScanViewController
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface MPScanCodeViewController : TBScanViewController<TBScanViewControllerDelegate>
@end
NS_ASSUME_NONNULL_END
Inicializar el ViewController de escaneo personalizado
// Custom scan entry point
- (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;
}
Utilice únicamente el método -(instancetype)initWithConfig:(NSDictionary *)config; para inicializar el ViewController de escaneo personalizado.
Personalizar el cuadro de escaneo
- (void)buildContainerView:(UIView*)containerView
{
// Custom 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];
}
Gestionar los resultados del escaneo
Los usuarios deben gestionarlos según sus propios escenarios de negocio.
#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];
});
}