在视频直播源码中实现二维码扫描功能,要怎么做?
2021/6/4 20:25:40
本文主要是介绍在视频直播源码中实现二维码扫描功能,要怎么做?,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在视频直播源码开发过程中,有时会需要用到二维码扫描功能,用户只要点开系统自带的摄像头,就能够扫描二维码,那么,这一功能该如何去实现呢?
一、 视频直播源码实现摄像头扫描
if (!_scanView) { _scanView = [[SGQRCodeScanView alloc] initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-64-statusbarHeight)]; _scanView.scanImageName = @"SGQRCode.bundle/QRCodeScanLineGrid"; _scanView.scanAnimationStyle = ScanAnimationStyleGrid; _scanView.cornerLocation = CornerLoactionOutside; _scanView.cornerColor = [UIColor orangeColor]; } YBWeakSelf; SGQRCodeObtainConfigure *configure = [SGQRCodeObtainConfigure QRCodeObtainConfigure]; configure.sampleBufferDelegate = YES; [obtain establishQRCodeObtainScanWithController:self configure:configure]; [obtain setBlockWithQRCodeObtainScanResult:^(SGQRCodeObtain *obtain, NSString *result) { if (result) { [obtain stopRunning]; [obtain playSoundName:@"SGQRCode.bundle/sound.caf"]; NSLog(@"===%@",result); NSArray *resA = [result componentsSeparatedByString:@"&"]; NSArray *roomA = [NSArray array]; NSArray *channelA = [NSArray array]; NSLog(@"resA:%@",resA); for (NSString *needStr in resA) { if ([needStr containsString:@"roomid"]) { roomA = [needStr componentsSeparatedByString:@"="]; NSLog(@"roomA:%@",roomA); }else if([needStr containsString:@"channel"]){ channelA = [needStr componentsSeparatedByString:@"="]; NSLog(@"roomA:%@",channelA); } } if (roomA.count<2 ||channelA.count<2) { dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD showErrorInfo:@[YZMsg(@"信息错误"),@"QRScan"]]; }); return ; } [weakSelf qrReset:@{@"id":roomA[1],@"channel":channelA[1]}]; } }]; [obtain setBlockWithQRCodeObtainScanBrightness:^(SGQRCodeObtain *obtain, CGFloat brightness) { if (brightness < - 1) { [weakSelf.view addSubview:weakSelf.flashlightBtn]; } else { if (weakSelf.isSelectedFlashlightBtn == NO) { [weakSelf removeFlashlightBtn]; } } }];
二、在相册中进行选择
从相册中选择二维码后,视频直播源码应当有自助判断能力,确认该图片中是否具备二维码,超时未识别出二维码时,应当做出反馈
YBWeakSelf; [obtain establishAuthorizationQRCodeObtainAlbumWithController:nil]; if (obtain.isPHAuthorization == YES) { [self.scanView removeTimer]; } [obtain setBlockWithQRCodeObtainAlbumDidCancelImagePickerController:^(SGQRCodeObtain *obtain) { [weakSelf.view addSubview:weakSelf.scanView]; }]; [obtain setBlockWithQRCodeObtainAlbumResult:^(SGQRCodeObtain *obtain, NSString *result) { if (result == nil) { NSLog(@"暂未识别出二维码"); [MBProgressHUD showPop:@"未能识别"]; } else { NSLog(@"===res:%@",result); NSArray *resA = [result componentsSeparatedByString:@"&"]; NSArray *roomA = [NSArray array]; NSArray *channelA = [NSArray array]; NSLog(@"resA:%@",resA); for (NSString *needStr in resA) { if ([needStr containsString:@"roomid"]) { roomA = [needStr componentsSeparatedByString:@"="]; NSLog(@"roomA:%@",roomA); }else if([needStr containsString:@"channel"]){ channelA = [needStr componentsSeparatedByString:@"="]; NSLog(@"roomA:%@",channelA); } } if (roomA.count<2 ||channelA.count<2) { dispatch_async(dispatch_get_main_queue(), ^{ [MBProgressHUD showErrorInfo:@[YZMsg(@"信息错误"),@"QRScan"]]; }); return ; } [weakSelf qrReset:@{@"id":roomA[1],@"channel":channelA[1]}]; } }];
三、销毁移除二维码
在使用完后,该二维码无需被保留,视频直播源码中应当编辑一串代码保障用户信息不受侵犯,以下是销毁移除的代码:
[self.scanView removeTimer]; [self removeFlashlightBtn]; [obtain stopRunning];
这篇关于在视频直播源码中实现二维码扫描功能,要怎么做?的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南