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;