二维码扫描 + 指纹识别

Demo

//1.系统
import AVFoundation/AVFoundation.h

//ZBar
//ZXing

//指纹识别
import LocalAuthentication/LocalAuthentication.h

@interface ViewController ()

@property (nonatomic,strong) AVCaptureSession *seession;

@end

@implementation ViewController

-(void)QRCode
{
self.seession = [[AVCaptureSession alloc] init];

//设置会话的质量
self.seession.sessionPreset = AVCaptureSessionPresetHigh;

//初始化设备:摄像头
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

//增加输入设备
AVCaptureDeviceInput *deviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:device error:nil];

[self.seession addInput:deviceInput];

//添加输出
AVCaptureMetadataOutput *outPut = [[AVCaptureMetadataOutput alloc] init];

[self.seession addOutput:outPut];

//设置代理
[outPut setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];

//设置输出类型
//AVMetadataObjectTypeQRCode  二维码
[outPut setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]];

//设置扫描区域
AVCaptureVideoPreviewLayer *layer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.seession];

layer.frame = CGRectMake(100, 100, 200, 200);

layer.videoGravity = AVLayerVideoGravityResizeAspectFill;

[self.view.layer insertSublayer:layer atIndex:0];

//开启扫描
[self.seession startRunning];

}

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    LAContext *context = [[LAContext alloc] init];

    //判断是否支持指纹识别
    if([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil])
    {
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@”登录” reply:^(BOOL success, NSError * _Nullable error) {

        if(success)
        {
            NSLog(@"验证成功");
        }
        else
        {
            NSLog(@"验证失败");
        }
    }];
    

    }
    else
    {
    NSLog(@”不支持指纹验证”);
    }
    }

  • (void)captureOutput:(AVCaptureOutput )captureOutput didOutputMetadataObjects:(NSArray )metadataObjects fromConnection:(AVCaptureConnection *)connection
    {
    NSLog(@”扫描成功 %@”,metadataObjects);

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[metadataObjects[0] stringValue]]];

    [self.seession stopRunning];
    }

猜你喜欢

转载自blog.csdn.net/weixin_35966617/article/details/53083263