Giter Site home page Giter Site logo

fytx113 / zrqrcodeviewcontroller Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 2.0 663 KB

A delightful QR Code Scanning framework that being compatible with iOS 7.0 and later. QRCode for iOS by using Objective-C.

License: MIT License

Objective-C 99.25% Ruby 0.75%

zrqrcodeviewcontroller's Introduction

ZRQRCodeViewController

A delightful QR Code Scanning framework that being compatible with iOS 7.0 and later. It has strongly precision to scan QR Code. It can scan QR Code and Bar Code.

滚动到最下面有中文说明

CSDN博文

How to get started


Installation


CocoaPods is a dependency manager for Objective-C , which anutomates and simplifies the process of using 3rd-party libraries like ZRQRCodeViewController in you projects.

$ gem install cocoapods

Cocoapods 1.0.0+ is required to build ZRQRCodeViewController 2.7.2

podfile

To integrate ZRQRCodeViewController into your Xcode project using Cocoapods, specify it in your Podfile:

source 'https://github.com/VictorZhang2014/ZRQRCodeViewController'
platform :ios, '7.0'  

pod 'ZRQRCodeViewController', '~>2.7.2'

Then, run the following command:

$ pod install

Usage


QR Code scan by camera, once a result ,after that, will close the current controller

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn];
qrCode.qrCodeNavigationTitle = @"QR Code Scanning";
[qrCode QRCodeScanningWithViewController:self completion:^(NSString *strValue) {
   NSLog(@"strValue = %@ ", strValue);
   if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
   } else {
       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
       [alertView show];
   }
}];

QR Code scan by camera, once a result, after that , won't close the current controller

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeContinuation];
[qrCode QRCodeScanningWithViewController:self completion:^(NSString *strValue) {
   NSLog(@"strValue = %@ ", strValue);
   if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
   } else {
       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
       [alertView show];
   }
}];

QR Code scan by camera , once a result , after that, will close the current controller. Its view can custom

    UIColor *white = [UIColor whiteColor];
    ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn customView:self.view navigationBarTitle:@"QR Code"];
    qrCode.VCTintColor = white; 
    [qrCode QRCodeScanningWithViewController:self completion:^(NSString *strValue) {
        NSLog(@"strValue = %@ ", strValue);
        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];

QR Code scan from the Photo Library

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn];
qrCode.textWhenNotRecognized = @"No any QR Code texture on the picture were found!";
[qrCode recognizationByPhotoLibraryViewController:self completion:^(NSString *strValue) {
   NSLog(@"strValue = %@ ", strValue);
   [[ZRAlertController defaultAlert] alertShow:self title:@"" message:[NSString stringWithFormat:@"Result: %@", strValue] okayButton:@"Ok" completion:^{
        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];
}];

QR Code scan by long-press that object, which is one of them ,UIImageView, UIButton, UIWebView, WKWebView, UIView, UIViewController

Note: Bind long-press gesture first, then using.

       Like this variable `self.imageViewExample` that 
       it needs the event of long-press. You can bind the gesture in the method `viewDidLoad()`.
ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn];
qrCode.cancelButton = @"Cancel";
qrCode.actionSheets = @[];
qrCode.extractQRCodeText = @"Extract QR Code";
NSString *savedImageText = @"Save Image";
qrCode.saveImaegText = savedImageText;
[qrCode extractQRCodeByLongPressViewController:self Object:self.imageViewExample actionSheetCompletion:^(int index, NSString * _Nonnull value) {
    if ([value isEqualToString:savedImageText]) {
       [[ZRAlertController defaultAlert] alertShow:self title:@"" message:@"Saved Image Successfully!" okayButton:@"Ok" completion:^{ }];
    }
} completion:^(NSString * _Nonnull strValue) {
    NSLog(@"strValue = %@ ", strValue);
    [[ZRAlertController defaultAlert] alertShow:self title:@"" message:[NSString stringWithFormat:@"Result: %@", strValue] okayButton:@"Ok" completion:^{
        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];
}];

QR Code Scan by a custom View, There is a sample view name is ZRQRCodeScanView and use of snippet code below. There is a whole code in this project

//1.You just import this header file
#import "ZRQRCodeScanView.h"

//2.Easy to call
[[[ZRQRCodeScanView alloc] init] openQRCodeScan:self];

ZRQRCodeViewController

ZRQRCodeViewController是一个非常好用的二维码扫描框架,兼容iOS 7.0及以后的系统版本。 有很精确的扫描能力,识别二维码和条形码。

CSDN博文

如何开始


安装


CocoaPods Cocoapods是一个Objective-C的库文件依赖管理器,它会自动的,简单化的集成第三方库到你的项目,例如ZRQRCodeViewController。

$ gem install cocoapods

Cocoapods 1.0.0+ is required to build ZRQRCodeViewController 2.7.2

podfile

使用Cocoapods把ZRQRCodeViewController库集成到你的项目,podfile文件内容如下

source 'https://github.com/VictorZhang2014/ZRQRCodeViewController'
platform :ios, '7.0'  

pod 'ZRQRCodeViewController', '~>2.7.2'

接着,运行以下命令

$ pod install

使用方法


通过摄像头扫描二维码,扫描一次返回一个结果,并结束当前扫描控制器

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn];
qrCode.qrCodeNavigationTitle = @"QR Code Scanning";
[qrCode QRCodeScanningWithViewController:self completion:^(NSString *strValue) {
    NSLog(@"strValue = %@ ", strValue);
    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
    } else {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
        [alertView show];
    }
}];

通过摄像头扫描二维码,扫描一次返回一个结果,不结束当前扫描控制器

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeContinuation];
[qrCode QRCodeScanningWithViewController:self completion:^(NSString *strValue) {
     NSLog(@"strValue = %@ ", strValue);
     if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
     } else {
          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
          [alertView show];
     }
}];

通过摄像头扫描,扫描一次返回一个结果,会结束挡墙控制器,并且它的view可以自定义

    UIColor *white = [UIColor whiteColor];
    ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn customView:self.view navigationBarTitle:@"QR Code"];
    qrCode.VCTintColor = white; 
    [qrCode QRCodeScanningWithViewController:self completion:^(NSString *strValue) {
        NSLog(@"strValue = %@ ", strValue);
        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];

从手机相册中选择一张图片进行扫描,

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn];
qrCode.textWhenNotRecognized = @"No any QR Code texture on the picture were found!";
[qrCode recognizationByPhotoLibraryViewController:self completion:^(NSString *strValue) {
    NSLog(@"strValue = %@ ", strValue);
    [[ZRAlertController defaultAlert] alertShow:self title:@"" message:[NSString stringWithFormat:@"Result: %@", strValue] okayButton:@"Ok" completion:^{
         if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
         } else {
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
             [alertView show];
         }
    }];
}];

通过长按要被扫描的对象,它可以是这些UIImageView, UIButton, UIWebView, WKWebView, UIView, UIViewController

注意: 先绑定长按手势,再使用。

例如这个变量,self.imageViewExample 它需要长按事件。可以在 viewDidLoad()方法中绑定该手势

ZRQRCodeViewController *qrCode = [[ZRQRCodeViewController alloc] initWithScanType:ZRQRCodeScanTypeReturn];
qrCode.cancelButton = @"Cancel";
qrCode.actionSheets = @[];
qrCode.extractQRCodeText = @"Extract QR Code";
NSString *savedImageText = @"Save Image";
qrCode.saveImaegText = savedImageText;
[qrCode extractQRCodeByLongPressViewController:self Object:self.imageViewExample actionSheetCompletion:^(int index, NSString * _Nonnull value) {
    if ([value isEqualToString:savedImageText]) {
         [[ZRAlertController defaultAlert] alertShow:self title:@"" message:@"Saved Image Successfully!" okayButton:@"Ok" completion:^{ }];
    }
} completion:^(NSString * _Nonnull strValue) {
    NSLog(@"strValue = %@ ", strValue);
    [[ZRAlertController defaultAlert] alertShow:self title:@"" message:[NSString stringWithFormat:@"Result: %@", strValue] okayButton:@"Ok" completion:^{
        if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:strValue]]){
             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strValue]];
        } else {
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ooooops!" message:[NSString stringWithFormat:@"The result is %@", strValue] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
             [alertView show];
        }
    }];
}];

二维码扫描可以通过自定View, 这里有一个样例,文件名是ZRQRCodeScanView,以下是使用代码,完整的代码请试运行该项目

//1.导入头文件
#import "ZRQRCodeScanView.h"

//2.调用超简单
[[[ZRQRCodeScanView alloc] init] openQRCodeScan:self];

zrqrcodeviewcontroller's People

Contributors

victorzhang2014 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.