QRCode Two-dimensional code learning:
Need to pour a frame avfoundation
1. An input device is required,
2. Output device (parsing the contents of the input device)
3 A session class (input and output is finished, which one is the input which is the output)
Avcapturesession
4. A display scan of the content layer
Two: Then create
Three: Set up proxy-get data
The session class does not know which one is the input device and which one is the output device need to connect them
To bind the input and output devices (to make a judgment),
Four: Set Scan type
Five: Start scanning
[Self.session startrunning]
Six: Complete the agent method to process the QR code
Scan to an array of data
Also need to find a class (is a type of) (The detail header file is not prompted) jump into the method
Get to the data there are two properties Obj.stringvalue
Seven: in iOS9 another special service can be easily displayed without loading the WebView page
Details: (Bring something similar to the navigation bar to complete the refresh also with share is the real browser of the system)
The advantage: The page is too long in the process of scrolling is not the Tabbar and navigation bar
The Tabbar and navigation bar are displayed only at the top.
And if your Sfsafariviewcontroller
//
Gasscanviewcontroller.m
Gasmanger
//
Created by Ninesday on 16/6/1.
COPYRIGHT©2016 year Ninesday. All rights reserved.
//
#import "GASScanViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <SafariServices/SafariServices.h>
@interface Gasscanviewcontroller () <AVCaptureMetadataOutputObjectsDelegate>
1. Input device
@property (Nonatomic,strong) avcapturedeviceinput *input;
2. Output device
@property (Nonatomic,strong) avcapturemetadataoutput *output;
3. Session Class
@property (Nonatomic,strong) avcapturesession *session;
4. Scan to layer of content
@property (Nonatomic,strong) Avcapturevideopreviewlayer *previewlayer;
@end
@implementation Gasscanviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Do any additional setup after loading the view.
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *) Event {
Input device
You have to create the device first
Avcapturedevice * device = [Avcapturedevice defaultdevicewithmediatype:avmediatypevideo];
Self.input = [[Avcapturedeviceinput alloc]initwithdevice:device Error:nil];
Output device
Self.output = [Avcapturemetadataoutput new];
Session class
Self.session = [Avcapturesession new];
Binding devices
if ([Self.session canAddInput:self.input]) {
[Self.session AddInput:self.input];
}
if ([Self.session canAddOutput:self.output]) {
[Self.session AddOutput:self.output];
}
Set up proxy to get data
[Self.output setmetadataobjectsdelegate:self Queue:dispatch_get_main_queue ()];
Set the type of scan
[Self.output Setmetadataobjecttypes:@[avmetadataobjecttypeqrcode]];
Scan to content layer--need to set up session
Self.previewlayer = [[Avcapturevideopreviewlayer alloc]initwithsession:self.session];
Self.previewlayer.frame = Self.view.bounds;
[Self.view.layer AddSublayer:self.previewlayer];
Start scanning
[Self.session startrunning];
}
/*
#pragma mark-navigation
In a storyboard-based application, you'll often want to do a little preparation before navigation
-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {
Get The new view controller using [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
}
*/
-(void) Captureoutput: (Avcaptureoutput *) captureoutput didoutputmetadataobjects: (Nsarray *) metadataobjects Fromconnection: (avcaptureconnection *) connection {
if (Metadataobjects.count >0) {
1. Stop scanning
[Self.session stoprunning];
Delete Layer
[Self.previewlayer Removefromsuperlayer];
Get data Avmetadatamachinereadablecodeobject header file not prompt
Avmetadatamachinereadablecodeobject *obj = metadataobjects[0];
NSLog (@ "%@", Obj.stringvalue);
if ([Obj.stringvalue hasprefix:@ "http"]) {
IOS9 new additions to the
Sfsafariviewcontroller *SF = [[Sfsafariviewcontroller alloc]initwithurl:[nsurl URLWithString:obj.stringValue]];
[Self presentviewcontroller:sf animated:sf completion:nil];
}
}
}
@end
8:2-dimensional Code optimization
To import a encapsulated class
Reset Type
Scanning of QR code
The IOS7 platform is followed by a popular framework Zbar ZXing
Summarize:
1. Input device
2. Output
3. Session
4. Agent
5. Scan type
6. Display the scanned content
7. Start scanning
8. Parsing in Proxy methods
1. Stop scanning
2. Delete Layer
3. Get data Avmetadatamachreadablecodeobject header file not prompt
iOS QR code (qrcode) Learning