Topik ini menjelaskan cara menggunakan SDK pengenalan multi-kode Scan dengan garis dasar kustom cp_change_28238 atau garis dasar 10.2.3.5 dan versi yang lebih baru. Anda dapat mengintegrasikan SDK pengenalan multi-kode ke dalam klien iOS berdasarkan proyek yang sudah ada menggunakan CocoaPods.
Prasyarat
Anda telah menghubungkan proyek Anda ke mPaaS. Untuk informasi selengkapnya, lihat Berbasis proyek yang sudah ada menggunakan CocoaPods.
Tambahkan SDK
Gunakan plugin cocoapods-mPaaS untuk menambahkan SDK pengenalan multi-kode. Prosedurnya sebagai berikut:
Pada file
Podfile, ubah mPaaS_baseline menjadicp_change_28238atau garis dasar 10.2.3.5 atau versi yang lebih baru.Gunakan
mPaaS_pod "mPaaS_ScanCode"untuk menambahkan dependensi komponen Scan.
Klik di sini untuk mempelajari cara menggunakan CocoaPods. Kemudian, jalankan
pod installataupod updatedi command line sesuai kebutuhan untuk menyelesaikan integrasi.
Gunakan SDK
Buka halaman scan default
Bagian ini menggunakan demo resmi Scan untuk menjelaskan cara menggunakan SDK pengenalan multi-kode Scan dengan UI default pada garis dasar kustom cp_change_28238 atau garis dasar 10.2.3.5 dan versi yang lebih baru.
Buka halaman scan default dan proses hasil pemindaian.
#import <TBScanSDK/TBScanSDK.h> @interface MPScanDemoVC() @property(nonatomic, strong) TBScanViewController *scanVC; @end - (void)defaultScan { // Menentukan apakah entri album ditampilkan. [MPScanCodeAdapterInterface sharedInstance].shoulShowAlbum = NO; TBScanViewController *vc = [[MPScanCodeAdapterInterface sharedInstance] createDefaultScanPageWithallback:^(id _Nonnull result, BOOL keepAlive) { // Proses hasil pemindaian. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:result[@"resp_result"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; alert.tag = 1999; [alert show]; }]; // Atur jenis pemindaian. vc.scanType = ScanType_Default_Code; [self.navigationController pushViewController:vc animated:YES]; self.scanVC = vc; }Untuk pengenalan multi-kode, aktifkan pemindaian berkelanjutan.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // Lanjutkan pemindaian. [self.scanVC resumeCaptureSession]; }
Cara menggunakan UI kustom
Bagian ini menggunakan demo resmi Scan untuk menjelaskan cara menggunakan SDK pengenalan multi-kode Scan dengan UI kustom.
Buat ViewController kustom yang mewarisi dari TBScanViewController
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface MPScanCodeViewController : TBScanViewController<TBScanViewControllerDelegate>
@end
NS_ASSUME_NONNULL_ENDInisialisasi ViewController scan kustom
// Titik masuk scan kustom
- (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;
}Hanya gunakan metode -(instancetype)initWithConfig:(NSDictionary *)config; untuk menginisialisasi ViewController scan kustom.
Kustomisasi kotak pemindaian
- (void)buildContainerView:(UIView*)containerView
{
// Tampilan kotak pemindaian kustom
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];
}Menangani hasil pemindaian
Pengguna menanganinya sesuai skenario bisnis masing-masing.
#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 adalah %@, ScanType_QRCode adalah %@", @(result.subType), @(ScanType_QRCode));
} else if (result.resultType == TBScanResultTypeVLGen3Code) {
content = [NSString stringWithFormat:@"gen3:%@", result.data];
NSLog(@"subType adalah %@, ScanType_GEN3 adalah %@", @(result.subType), @(ScanType_GEN3));
} else if (result.resultType == TBScanResultTypeGoodsBarcode) {
content = [NSString stringWithFormat:@"barcode:%@", result.data];
NSLog(@"subType adalah %@, EAN13 adalah %@", @(result.subType), @(EAN13));
} else if (result.resultType == TBScanResultTypeDataMatrixCode) {
content = [NSString stringWithFormat:@"dm:%@", result.data];
NSLog(@"subType adalah %@, ScanType_DATAMATRIX adalah %@", @(result.subType), @(ScanType_DATAMATRIX));
} else if (result.resultType == TBScanResultTypeExpressCode) {
content = [NSString stringWithFormat:@"express:%@", result.data];
NSLog(@"subType adalah %@, ScanType_FASTMAIL adalah %@", @(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];
});
}