Unsupported type found appears after iOS7 with Avcapture. Use-availablemetadataobjecttypes the wrong solution

Source: Internet
Author: User

In the integration scan QR code function, I use the system after iOS7.0 to support the scan QR Code function class. This is how the code was created.

1-(void) Setupcamera2 {3Self.device =[Avcapturedevice Defaultdevicewithmediatype:avmediatypevideo];4     5Self.input =[Avcapturedeviceinput deviceInputWithDevice:self.device error:nil];6     7Self.output =[[Avcapturemetadataoutput alloc]init];8Self.outPut.metadataObjectTypes =@[avmetadataobjecttypeqrcode]; 9 [_output setmetadataobjectsdelegate:self queue:dispatch_get_main_queue ()];TenSelf.session =[[Avcapturesession alloc]init]; One [Self.session Setsessionpreset:avcapturesessionpresethigh]; A     if([self.session canAddInput:self.input]) -     { - [Self.session addInput:self.input]; the          -     } -      -     if([self.session canAddOutput:self.outPut]) +     { - [Self.session AddOutput:self.outPut]; +     } A      at  -_preview =[Avcapturevideopreviewlayer layerWithSession:self.session]; -_preview.videogravity =Avlayervideogravityresizeaspectfill; -_preview.frame =cgrectmake ( -, the,280,280); -[Self.view.layer InsertSublayer:self.preview Atindex:0]; -  in [Self.session startrunning]; -}

In its proxy class

-(void) Captureoutput: (Avcaptureoutput *) captureoutput didoutputmetadataobjects: (Nsarray *) metadataobjects fromConnection :(Avcaptureconnection *) connection{NSString*StringValue; if([metadataobjects Count] >0) {Avmetadatamachinereadablecodeobject*metadataobject = [Metadataobjects objectatindex:0]; StringValue=Metadataobject.stringvalue;    } [Self.session stoprunning]; [Self Dismissviewcontrolleranimated:yes completion:^{[Timer invalidate]; Uialertview*alertview = [[Uialertview alloc]initwithtitle:@"Two-dimensional code related content"Message:stringvalueDelegate: Nil Cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Determine", nil];            [Alertview show]; }];}

Test on the real machine, the system is iOS7.1.1

The following error occurred at run time:

Terminating app due to uncaught exception ' nsinvalidargumentexception ', Reason: ' * * *-[avcapturemetadataoutput Setmet adataobjecttypes:]–unsupported type found. Use-availablemetadataobjecttypes. '

Can't solve, search on the internet there is no relevant solution, finally find the relevant documents and see the manual, or can not solve the problem, ask a great God, viewing the system Help document Avmetadataobjecttypes changed the creation of code block-(void) Setupcamera as follows;

-(void) setupcamera{Self.device=[Avcapturedevice Defaultdevicewithmediatype:avmediatypevideo]; Self.input=[Avcapturedeviceinput DeviceInputWithDevice:self.device Error:nil]; Self.output=[[Avcapturemetadataoutput alloc]init];//self.outPut.metadataObjectTypes = @[avmetadataobjecttypeqrcode];//self.outPut.metadataObjectTypes = @[avmetadataobjecttypeqrcode];[_output setmetadataobjectsdelegate:self queue:dispatch_get_main_queue ()]; Self.session=[[Avcapturesession alloc]init];    [Self.session Setsessionpreset:avcapturesessionpresethigh]; if([self.session canAddInput:self.input]) {[Self.session addInput:self.input]; }        if([self.session CanAddOutput:self.outPut]) {[Self.session addOutput:self.outPut]; } self.outPut.metadataObjectTypes=[Nsarray Arraywithobject:avmetadataobjecttypeqrcode]; _preview=[Avcapturevideopreviewlayer layerWithSession:self.session]; _preview.videogravity=Avlayervideogravityresizeaspectfill; _preview.frame=cgrectmake ( -, the,280,280); [Self.view.layer insertSublayer:self.preview Atindex:0]; [Self.session startrunning];}

So the problem is solved.

The Great God explains the official documents in the general sense:

The object of the Avcapturemetadataoutput class (in this case, self.output), The properties of the Self.output metadataobjecttypes to be in the Avcapturesession class object (this example is Self.session)

[Self.session AddOutput:self.outPut] is the addition of Avcapturemetadataoutput objects, before they can be set;

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.