仿微信二維碼掃描:QRCodeReaderViewController

仿微信二維碼掃描。

QRCodeReaderViewController

The QRCodeReaderViewController was initialy a simple QRCode reader but it now lets you the possibility to specify the format type you want to decode. It is based on theAVFoundationframework from Apple in order to replace ZXing or ZBar for iOS 7 and over.

It provides a default view controller to display the camera view with the scan area overlay and it also provides a button to switch between the front and the back cameras.

screenshot

Installation

The recommended approach to use QRCodeReaderViewController in your project is using the CocoaPods package manager, as it provides flexible dependency management and dead simple installation.

CocoaPods

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Go to the directory of your Xcode project, and Create and Edit your Podfile and add QRCodeReaderViewController:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile source 'https://github.com/CocoaPods/Specs.git' platform :ios, '7.0' pod 'QRCodeReaderViewController', '~> 3.5.2'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file)

$ open MyProject.xcworkspace

Manually

Download the project and copy theQRCodeReaderViewControllerfolder into your project and then simply#import "QRCodeReaderViewController.h"in the file(s) you would like to use it in.

Usage

- (IBAction)scanAction:(id)sender
{
  NSArray *types = @[AVMetadataObjectTypeQRCode];
  _reader        = [QRCodeReaderViewController readerWithMetadataObjectTypes:types];

  // Set the presentation style
  _reader.modalPresentationStyle = UIModalPresentationFormSheet;

  // Using delegate methods
  _reader.delegate = self;

  // Or by using blocks
  [_reader setCompletionWithBlock:^(NSString *resultAsString) {
    [self dismissViewControllerAnimated:YES completion:^{
      NSLog(@"%@", resultAsString);
    }];
  }];

  [self presentViewController:_reader animated:YES completion:NULL];
}

#pragma mark - QRCodeReader Delegate Methods

- (void)reader:(QRCodeReaderViewController *)reader didScanResult:(NSString *)result
{
  [self dismissViewControllerAnimated:YES completion:^{
    NSLog(@"%@", result);
  }];
}

- (void)readerDidCancel:(QRCodeReaderViewController *)reader
{
  [self dismissViewControllerAnimated:YES completion:NULL];
}

項目主頁:http://www.baiduhome.net/lib/view/home/1443428329971

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!