更新时间:2020-09-14 15:00
扫一扫 SDK 是支付宝目前正在使用的识别二维码、条形码等功能的 SDK 。本文将向您介绍如何使用扫一扫 SDK。
您已经根据您的接入方式,将扫一扫组件 SDK 添加至工程。更多信息,请参见以下内容:
根据您采用的接入方式,请选择相应的添加方式。
mPaaS_pod "mPaaS_ScanCode"
添加扫码组件依赖。pod install
即可完成接入。本文将结合 扫一扫 官方 Demo 介绍如何在 10.1.68.17 及以上版本的基线中使用扫一扫 SDK。
唤起默认扫码页面并处理扫描结果。
@interface MPScanDemoVC()<TBScanViewControllerDelegate>
@property(nonatomic, strong) TBScanViewController *scanVC;
@end
- (void)defaultScan {
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];
}];
[self.navigationController pushViewController:vc animated:YES];
self.scanVC = vc;
}
持续扫码。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// 持续扫码
[self.scanVC resumeScan];
}
本文将结合 扫一扫 官方 Demo 介绍如何在 10.1.68.17 以下版本的基线中使用扫一扫 SDK。
@interface MPScanDemoVC()<TBScanViewControllerDelegate>
@property(nonatomic, strong) TBScanViewController *scanVC;
@end
- (void)startDefauleScanViewController
{
TBScanViewController *vc = [[TBScanViewController alloc] init];
vc.scanType = ScanType_All_Code;
vc.delegate = self;
[self.navigationController pushViewController:vc animated:YES];
self.scanVC = vc;
}
处理扫描结果。
#pragma mark 处理扫描结果
-(void)didFind:(NSArray<TBScanResult*>*)resultArray
{
if([resultArray count] > 0) {
TBScanResult *result = resultArray.firstObject;
NSString* content = result.data;
dispatch_async(dispatch_get_main_queue(), ^{
// 注意:扫码的结果是在子线程,如有UI相关操作,请切换到主线程
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:content delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
});
}
}
#pragma mark alert
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[self.scanVC resumeScan];
}
在文档使用中是否遇到以下问题
更多建议
匿名提交