美文网首页
识别二维码

识别二维码

作者: 大鹏你我他 | 来源:发表于2018-07-18 14:42 被阅读0次

    -(void)dealLongPress:(UIGestureRecognizer*)gesture{

    if(gesture.state==UIGestureRecognizerStateBegan){

    UIImageView*tempImageView=(UIImageView*)gesture.view;

    if(tempImageView.image){

    //1. 初始化扫描仪,设置设别类型和识别质量

    CIDetector*detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];

    //2. 扫描获取的特征组

    NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:tempImageView.image.CGImage]];

    //3. 获取扫描结果

    CIQRCodeFeature *feature = [features objectAtIndex:0];

    NSString *scannedResult = feature.messageString;

    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"扫描结果" message:scannedResult delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    [alertView show];

    }else {

    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"扫描结果" message:@"您还没有生成二维码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    [alertView show];

    }

    }

    }

    相关文章

      网友评论

          本文标题:识别二维码

          本文链接:https://www.haomeiwen.com/subject/wvnljxtx.html