ios - How to scan all bar codes of type AVMetadataObjectTypeEAN13Code -
my scanner can scan barcode.
but not barcode.
this code i'm using.
#pragma mark - ibaction method implementation - (void)startstopreading { if (!_isreading) { // case app should read qr code when start button tapped. if ([self startreading]) { // if startreading methods returns yes , capture session // running, change start button title , status message. [_decodedlabel settext:@"scanning qr code..."]; } } else{ // in case app reading qr code , should stop doing so. [self stopreading]; // bar button item's title should change again. } // set flag exact opposite value of 1 has. _isreading = !_isreading; } #pragma mark - private method implementation - (bool)startreading { nserror *error; // instance of avcapturedevice class initialize device object , provide video // media type parameter. avcapturedevice *capturedevice = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo]; // instance of avcapturedeviceinput class using previous device object. avcapturedeviceinput *input = [avcapturedeviceinput deviceinputwithdevice:capturedevice error:&error]; if (!input) { // if error occurs, log description of , don't continue more. nslog(@"%@", [error localizeddescription]); return no; } // initialize capturesession object. _capturesession = [[avcapturesession alloc] init]; // set input device on capture session. [_capturesession addinput:input]; // initialize avcapturemetadataoutput object , set output device capture session. avcapturemetadataoutput *capturemetadataoutput = [[avcapturemetadataoutput alloc] init]; [_capturesession addoutput:capturemetadataoutput]; // create new serial dispatch queue. dispatch_queue_t dispatchqueue; dispatchqueue = dispatch_queue_create("myqueue", null); [capturemetadataoutput setmetadataobjectsdelegate:self queue:dispatchqueue]; [capturemetadataoutput setmetadataobjecttypes:[nsarray arraywithobject:avmetadataobjecttypeean13code]]; // initialize video preview layer , add sublayer viewpreview view's layer. _videopreviewlayer = [[avcapturevideopreviewlayer alloc] initwithsession:_capturesession]; [_videopreviewlayer setvideogravity:avlayervideogravityresizeaspectfill]; [_videopreviewlayer setframe:_viewpreview.layer.bounds]; [_viewpreview.layer addsublayer:_videopreviewlayer]; // start video capture. [_capturesession startrunning]; return yes; } -(void)stopreading{ // stop video capture , make capture session object nil. [_capturesession stoprunning]; _capturesession = nil; // remove video preview layer viewpreview view's layer. [_videopreviewlayer removefromsuperlayer]; } #pragma mark - avcapturemetadataoutputobjectsdelegate method implementation -(void)captureoutput:(avcaptureoutput *)captureoutput didoutputmetadataobjects:(nsarray *)metadataobjects fromconnection:(avcaptureconnection *)connection{ // check if metadataobjects array not nil , contains @ least 1 object. if (metadataobjects != nil && [metadataobjects count] > 0) { // metadata object. avmetadatamachinereadablecodeobject *metadataobj = [metadataobjects objectatindex:0]; if ([[metadataobj type] isequaltostring:avmetadataobjecttypeean13code]) { // if found metadata equal qr code metadata update status label's text, // stop reading , change bar button item's title , flag's value. // done on main thread. [_decodedlabel performselectoronmainthread:@selector(settext:) withobject:[metadataobj stringvalue] waituntildone:no]; [self performselectoronmainthread:@selector(stopreading) withobject:nil waituntildone:no]; _isreading = no; [self barcodereadgotonextpage:[metadataobj stringvalue]]; // if audio player not nil, play sound effect. if (_audioplayer) { [_audioplayer play]; } } } }
how can work barcodes of type avmetadataobjecttypeean13code
Comments
Post a Comment