ios7+ scanning QR codes and barcodes for time-consuming operation

Source: Internet
Author: User

IOS7 used to use zxing Zbar to achieve scanning QR code and bar code, from the IOS7 out, the system comes with the API is very powerful, and gradually gave up the use of zxing Zbar,

Directly on the main code:

- (void) setupcamera{Dispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_default,0), ^{[Hudutils showhudprogress:@""]; Avauthorizationstatus Authstatus=[Avcapturedevice Authorizationstatusformediatype:avmediatypevideo]; if(Authstatus = = avauthorizationstatusauthorized) {//has been authorized                }Else{//No authorizationNSString*Recommand; if(is_ios_8) {Recommand=@"Unable to open camera, go to settings and continue operation \ n Settings ---good business--camera"; }Else{Recommand=@"Unable to receive push message, please go to settings and continue operation \ n Settings ---privacy--camera--good business"; } Uialertview*alert = [[Uialertview alloc]initwithtitle:@"Tips"Message:recommandDelegate: Nil Cancelbuttontitle:@"Determine"Otherbuttontitles:nil];            [Alert show]; return; }            ///Device_device=[Avcapturedevice Defaultdevicewithmediatype:avmediatypevideo]; //Input_input=[Avcapturedeviceinput DeviceInputWithDevice:self.device Error:nil]; //Output_output=[[Avcapturemetadataoutput alloc] init];        [_output setmetadataobjectsdelegate:self Queue:dispatch_get_main_queue ()]; _output.rectofinterest=Self.scanImageView.bounds; //Session_session=[[Avcapturesession alloc]init];        [_session Setsessionpreset:avcapturesessionpresethigh]; if([_session canAddInput:self.input]) {[_session addInput:self.input]; }            if([_session canAddOutput:self.output]) {[_session addOutput:self.output]; }            //Barcode Type Avmetadataobjecttypeqrcode_output.metadataobjecttypes=@[avmetadataobjecttypeqrcode,avmetadataobjecttypeean13code,avmetadataobjecttypeean8code,        Avmetadataobjecttypeupcecode]; Dispatch_async (Dispatch_get_main_queue (),^{    //Preview[hudutils dismiss]; _preview=[Avcapturevideopreviewlayer layerWithSession:self.session]; _preview.videogravity=Avlayervideogravityresizeaspectfill; _preview.frame=Self.view.frame; [Self.view.layer insertSublayer:self.preview Atindex:0]; /*Configure color to start outside viewfinder*/        //ScancropUIView*viewtopscan =[[UIView alloc] Initwithframe:cgrectmake (0,0, ScreenWidth, Self.scanImageView.top)]; UIView*viewbottomscan =[[UIView alloc] Initwithframe:cgrectmake (0, Self.scanImageView.bottom, ScreenWidth, ScreenHeight-Self.scanImageView.bottom)]; UIView*viewleftscan =[[UIView alloc] Initwithframe:cgrectmake (0, Self.scanImageView.top, (screenwidth-self.scanimageview.width)/2, Self.scanImageView.height)]; UIView*viewrightscan =[[UIView alloc] Initwithframe:cgrectmake (Self.scanImageView.right, Self.scanImageView.top, (ScreenWidth-self.scanimageview.width)/2, Self.scanImageView.height)]; Viewtopscan.backgroundcolor= [Uicolor colorwithred:0.0Green0.0Blue0.0Alpha0.2]; Viewbottomscan.backgroundcolor= [Uicolor colorwithred:0.0Green0.0Blue0.0Alpha0.2]; Viewleftscan.backgroundcolor= [Uicolor colorwithred:0.0Green0.0Blue0.0Alpha0.2]; Viewrightscan.backgroundcolor= [Uicolor colorwithred:0.0Green0.0Blue0.0Alpha0.2];        [Self.view Addsubview:viewtopscan];        [Self.view Addsubview:viewbottomscan];        [Self.view Addsubview:viewleftscan];            [Self.view Addsubview:viewrightscan]; /*Configure viewfinder outside the color end*/Self.contentLable.layer.cornerRadius= Self.contentLable.height/2 ; Self.contentLable.layer.backgroundColor= [[Uicolor colorwithred:0.0Green0.0Blue0.0Alpha0.8] Cgcolor]; //Start[_session startrunning];    }); });}

One thing to note is that when initializing a camera, it can be time-consuming, especially apparent on the iphone 4 machine, and simple, plus an asynchronous operation to solve the problem.

ios7+ scanning QR codes and barcodes for time-consuming operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.