このトピックでは、カスタムベースライン cp_change_28238 またはベースラインバージョン 10.2.3.5 以降で、スキャン SDK の複数コード認識機能を使用する方法について説明します。複数コード認識 SDK を CocoaPods を使用したネイティブプロジェクトに基づいて iOS クライアントに統合できます。
前提条件
プロジェクトを mPaaS に接続済みであること。詳細については、「ネイティブフレームワークと Cocoapods を使用したアクセス」をご参照ください。
SDK の追加
CocoaPods プラグインを使用して、複数コード認識 SDK を追加します。次の手順を実行します。
Podfileファイルを開き、mPaaS_baseline をcp_change_28238またはベースラインバージョン 10.2.3.5 以降に変更します。mPaaS_pod "mPaaS_ScanCode"を実行して、スキャンコンポーネントの依存関係を追加します。
ここをクリックして、CocoaPods の使用方法を確認します。CLI で、
pod installまたはpod updateを実行して SDK を追加します。
SDK の使用
このセクションでは、カスタマイズされたベースライン cp_change_28238 またはベースラインバージョン 10.2.3.5 以降で、スキャン SDK の複数コード認識機能を使用する方法について説明します。スキャン コンポーネントの公式デモを参考に使用します。
デフォルトのスキャンページを開く
複数コード認識機能は、標準 UI でのみ使用できます。
デフォルトのスキャンページをトリガーし、スキャン結果を処理します。
#import <TBScanSDK/TBScanSDK.h> @interface MPScanDemoVC() @property(nonatomic, strong) TBScanViewController *scanVC; @end - (void)defaultScan { // アルバムへのエントリを表示するかどうかを定義します。 [MPScanCodeAdapterInterface sharedInstance].shoulShowAlbum = NO; TBScanViewController *vc = [[MPScanCodeAdapterInterface sharedInstance] createDefaultScanPageWithallback:^(id _Nonnull result, BOOL keepAlive) { // スキャン結果を処理します。 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:result[@"resp_result"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; alert.tag = 1999; [alert show]; }]; // スキャンの種類を設定します。 vc.scanType = ScanType_Default_Code; [self.navigationController pushViewController:vc animated:YES]; self.scanVC = vc; }複数コード認識と連続コードスキャンを実行します。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // 連続コードスキャンを有効にします。 [self.scanVC resumeCaptureSession]; }
カスタム UI の使用方法
この記事では、スキャン 公式デモと併せて、カスタム UI で複数コード認識機能 SDK を使用する方法を紹介します。
TBScanViewController を継承する ViewController をカスタマイズする
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface MPScanCodeViewController : TBScanViewController<TBScanViewControllerDelegate>
@end
NS_ASSUME_NONNULL_ENDカスタムスキャン ViewController を初期化する
//カスタムスキャンエントリ
- (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;
}カスタムスキャンコードを初期化する ViewController は、-(instancetype)initWithConfig:(NSDictionary *)config; メソッドのみ使用できます。
スキャンボックスをカスタマイズする
- (void)buildContainerView:(UIView*)containerView
{
// スキャンボックスビューをカスタマイズする
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];
}スキャン結果を処理する
ユーザーは、独自のビジネスシナリオに応じて処理します。
#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];
});
}