二维码扫描 + 指纹识别

来源:互联网 发布:arr slice js 编辑:程序博客网 时间:2024/06/03 05:08

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];
    }

0 0
原创粉丝点击