IOS QR code scanning and ios Scanning
// Import the AVFoundation. framwork framework
# Import "HDCodeViewController. h "# import" HDNormalViewController. h "# import <AVFoundation/AVFoundation. h> @ interface HDCodeViewController () <AVCaptureMetadataOutputObjectsDelegate> @ property (strong, nonatomic) UIView * codeView; @ property (strong, nonatomic) UIImageView * myLine; @ end @ implementation HDCodeViewController {AVCaptureSession * _ session; NSString * _ theString; NSTimer * _ timer; BOOL _ upOrdown; NSInteger _ num;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. [self initUI]; [self prepareCamara]; [self initData];}-(void) dealloc {[_ timer invalidate]; _ timer = nil; _ session = nil ;} -(void) initData {_ num = 0 ;}# pragma mark-UI Stuff Methods-(void) initUI {self. codeView = [[UIView alloc] initWithFrame: CGRectMake (0, 44, SCREEN_WIDTH, SCREEN_HEIGHT-44)]; self. codeView. backgroundColor = [UIColor clearColor]; [self. view addSubview: self. codeView]; UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (SCREEN_WIDTH-300)/2, 20,300,300)]; imageView. image = [UIImage imageNamed: @ "code_square"]; [self. codeView addSubview: imageView]; self. myLine = [[UIImageView alloc] initWithFrame: CGRectMake (SCREEN_WIDTH-300)/2, 20,300, 2)]; self. myLine. contentMode = UIViewContentModeScaleToFill; self. myLine. image = [UIImage imageNamed: @ "code_movingBar"]; [self. codeView addSubview: self. myLine]; _ timer = [NSTimer scheduledTimerWithTimeInterval :. 02 target: self selector: @ selector (moveLine) userInfo: nil repeats: YES];}-(void) moveLine {CGFloat height = self. myLine. frame. origin. y; CGFloat width = self. myLine. frame. size. width; if (_ upOrdown = NO) {_ num ++; self. myLine. frame = CGRectMake (SCREEN_WIDTH-300)/2, height + 2, width, 2); if (2 * _ num = 300) {_ upOrdown = YES ;}} else {_ num --; self. myLine. frame = CGRectMake (SCREEN_WIDTH-300)/2, height-2, width, 2); if (_ num = 0) {_ upOrdown = NO ;}}} # pragma Camara Stuff Methods-(void) prepareCamara {AVCaptureDevice * device = [AVCaptureDevice failed: AVMediaTypeVideo]; required * input = [deviceInputWithDevice: device error: nil]; AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init]; [output setMetadataObjectsDelegate: self queue: queue ()]; _ session = [[AVCaptureSession alloc] init]; [_ session setSessionPreset: AVCaptureSessionPresetHigh]; [_ session addInput: input]; [_ session addOutput: output]; output. metadataObjectTypes = @ [AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code]; required * layer = [javaslayerwithsession: _ session]; layer. videoGravity = AVLayerVideoGravityResizeAspectFill; layer. frame = CGRectMake (SCREEN_WIDTH-300)/2, 20,300,300); [self. codeView. layer insertSublayer: layer atIndex: 0]; [_ session startRunning];}-(void) captureOutput :( AVCaptureOutput *) captureOutput failed :( NSArray *) metadataObjects fromConnection :( AVCaptureConnection *) connection {if (metadataObjects. count> 0) {// [session stopRunning]; AVMetadataMachineReadableCodeObject * metadataObject = [metadataObjects objectAtIndex: 0]; _ theString = metadataObject. stringValue; NSLog (@ "% @", _ theString); // The scanned string} @ end