I. Basic description
1. Integration mode
Manual import integration, Cocoapods does not respond to wait, do not know cocoapods version reason or what. Official integration document
2. How to implement Anyline plug-in
Starting with Anyline 4, each use case requires three components to scan successfully, which means you can add the following three components to the controller that you want to scan:
- ScanPlugin
Processing image recognition and scanning functions related to scanning functions are all handled by the plug-in
- ScanViewPlugin
Deal with UI-related, uI-related configuration
- ScanView
Scanview handles the camera, flash, and manages the scanviewPlugin and scanPlugin created earlier. The UI configuration is also presented by ScanView
3. Add plug-ins to the ViewController
Add a component to a controller
// The Anyline plugins used to scan
@property (nonatomic, strong) ALMeterScanViewPlugin *meterScanViewPlugin;
@property (nonatomic, strong) ALMeterScanPlugin *meterScanPlugin;
@property (nullable, nonatomic, strong) ALScanView *scanView;
Copy the code
4. Plug-in description
ScanPlugin initialization
Initialization requires a key generated on the web site
NSError *error = nil; //ALMeterScanPlugin = nil; //ALMeterScanPlugin = NSError *error = nil; self.meterScanPlugin = [[ALMeterScanPlugin alloc] initWithPluginID:@"ENERGY" licenseKey:kDemoAppLicenseKey delegate:self error:&error];
NSAssert(self.meterScanPlugin, @"Setup Error: %@", error.debugDescription);
Copy the code
In the code above, the key needs to be generated and the ID needs to be a unique string
ScanViewPlugin initialization
After the scanPlugin is initialized, the next step is to create the scanviewPlugin using the scanPlugin you just created. The scanviewPlugin handles and displays the UI for scanning.
//Add Meter Scan View Plugin (Scan UI)
self.meterScanViewPlugin = [[ALMeterScanViewPlugin alloc] initWithScanPlugin:self.meterScanPlugin];
Copy the code
Set the ScanViewPluginConfig
View The appearance of the scan process. You can perform the following operations to create a JSON file and set parameters in the file. For details, see the configuration description on the official website
NSString *confPath = [[NSBundle mainBundle] pathForResource:@"meter_capture_config" ofType:@"json"];
ALScanViewPluginConfig *scanViewPluginConfig = [ALScanViewPluginConfig configurationFromJsonFilePath:confPath];
self.meterScanViewPlugin = [[ALMeterScanViewPlugin alloc] initWithScanPlugin:self.meterScanPlugin
scanViewPluginConfig:scanViewPluginConfig];
Copy the code
ScanView
The last Anyline object you need to create is the so-called ScanView, which handles the camera, flash, and manages the scanviewPlugin and scanPlugin you created earlier. You need to instantiate scanView with the scanviewPlugin you created earlier. In general, this is what we see in the camera interface.
//Add ScanView (Camera and Flashbutton)
self.scanView = [[ALScanView alloc] initWithFrame:frame scanViewPlugin:self.meterScanViewPlugin];
[self.view addSubview:self.scanView];
[self.scanView startCamera];
Copy the code
Start scanning
Note: Before starting any behavior, make sure you use [scanView startCamera] in viewDidLoad.
/*
This method will be called once the view controller and its subviews have appeared on screen
*/
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
/*
This is the place where we tell Anyline to start receiving and displaying images from the camera.
Success/error tells us if everything went fine.
*/
NSError *error = nil;
BOOL success = [self.meterScanViewPlugin startAndReturnError:&error];
if( !success ) {
// Something went wrong. The error object contains the error description
[[[UIAlertView alloc] initWithTitle:@"Start Scanning Error"
message:error.debugDescription
delegate:self
cancelButtonTitle:@"OK"otherButtonTitles:nil] show]; }}Copy the code
Stop the scan
To stop the scanning process, call stopAndreTurnerror on the plug-in: To ensure that the SDK in right when you leave the activity to stop, at least ensure viewwilldisplases in uiviewcontroller: use stopandreturnerror lifecycle methods:
/*
Cancel scanning to allow the module to clean up
*/
- (void)viewWillDisappear:(BOOL)animated {
[self.meterScanViewPlugin stopAndReturnError:nil];
}
Copy the code
Check the expiration time of the key
Key expiration causes errors and provides a static method to check the expiration date of the license key string. Will return an NSString containing the date. If the license cannot be analyzed, an error is returned
NSError *error = nil;
NSString *dateString = [ALCoreController licenseExpirationDateForLicense:YOUR_LICENSE_KEY_STRING error:&error];
Copy the code
Some details and problems of specific development are explained in the follow-up….
Ii. Plug-in details
Anyline provides 6 kinds of plug-ins. Choose the right one according to the business. Here is a brief introduction of one of them, MeterPlugin
MeterPlugin
The Anyline energy plug-in is capable of scanning analog electricity, gas and water meter readings. Bar and QR codes can also be scanned, which is useful for identifying meters and serial numbers. Ordinary digital meters and heat meters can also be scanned.
If you want to implement this plug-in, you will need to implement all of the basics mentioned above, and a complete code will be presented at the end of this article. Let’s look at some details first.
Scan UI configuration related
NSString *confPath = [[NSBundle mainBundle] pathForResource:@"meter_capture_config" ofType:@"json"];
ALScanViewPluginConfig *scanViewPluginConfig = [ALScanViewPluginConfig configurationFromJsonFilePath:confPath];
self.meterScanViewPlugin = [[ALMeterScanViewPlugin alloc] initWithScanPlugin:self.meterScanPlugin
scanViewPluginConfig:scanViewPluginConfig];
Copy the code
The following code is the UI code for setting up the scan interface, which is important to generate a JSON file in the project to configure, using the above code as an example to create a new meter_capture_config. json file, such as setting the camera and flash button:
{
"camera": {
"captureResolution": "1080"."pictureResolution": "1080"."zoomGesture" : true."zoomRatio": 2."maxZoomRatio": 5},"flash": {
"mode": "manual"."alignment": "bottom_right"}},Copy the code
More UI configuration instructions
Setting scan Mode
The Meter plug-in for scanning water and electricity meters is further refined into a number of use cases. By setting the scan mode to the corresponding use cases, the related use cases can be launched from the Meter plug-in.
//Set ScanMode to ALAutoAnalogDigitalMeter Scan all types of analog meters (gas, electricity, water), automatically detect the number of digits before and after the decimal point, and 7-segment digital meters with at least 3 digits. BOOL success = [self.meterScanPluginsetScanMode:ALAutoAnalogDigitalMeter error:&error];
if( !success ) {
// Something went wrong. The error object contains the error description
[[[UIAlertView alloc] initWithTitle:@"Failed to set scan type"
message:error.debugDescription
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
Copy the code
Here is a diagram of the Meter plug-in’s scan pattern, illustrated here:
Scan result callback (TheMeterDelegate)
In the controller to follow the protocol < ALMeterScanPluginDelegate >, the proxy method anylineMeterScanPlugin: didFindScanResult: in the scan results are obtained
The obtained scan result is ALMeterResult, which contains the actual scan result, the scan image and the last processed full frame image
- ALMeterResult
Field | Type | Nullable | Description |
---|---|---|---|
result | NSString | ✗ | The actual results of the scanning process |
image | UIImage | ✓ | Cropped images in a scan |
fullImage | UIImage | ✓ | Full image |
confidence | NSInteger | ✓ | Accuracy of scan results |
#pragma mark - ALMeterScanPluginDelegate methods
/*
The main delegate method Anyline uses to report its scanned codes
*/
- (void)anylineMeterScanPlugin:(ALMeterScanPlugin *)anylineMeterScanPlugin
didFindResult:(ALMeterResult *)scanResult {
[self anylineDidFindResult:scanResult.result barcodeResult:self.barcodeResult image:(UIImage*)scanResult.image scanPlugin:anylineMeterScanPlugin viewPlugin:self.meterScanViewPlugin completion:^{
//Display the result
}];
}
Copy the code
A complete code:
/ / / / SHMeterScanViewController. M / / TimeHomeApp / / / / Created by ning on 2019/9/26. / / Copyright © 2019 SafeHome. All rights reserved. //#import "SHMeterScanViewController.h"
#import <Anyline/Anyline.h>
#define kDemoAppLicenseKey @define kDemoAppLicenseKey
@interface SHMeterScanViewController ()<ALMeterScanPluginDelegate>
@property (nonatomic, strong) ALMeterScanViewPlugin *meterScanViewPlugin;
@property (nonatomic, strong) ALMeterScanPlugin *meterScanPlugin;
@property (nullable, nonatomic, strong) ALScanView *scanView;
@end
@implementation SHMeterScanViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *confPath = [[NSBundle mainBundle] pathForResource:@"vin_capture_config" ofType:@"json"];
//Initiate the ALScanViewPluginConfig with the JSON file
ALScanViewPluginConfig *scanViewPluginConfig = [ALScanViewPluginConfig configurationFromJsonFilePath:confPath];
NSError *error = nil;
self.meterScanPlugin = [[ALMeterScanPlugin alloc] initWithPluginID:@"ENERGY" licenseKey:kDemoAppLicenseKey delegate:self error:&error];
self.meterScanViewPlugin = [[ALMeterScanViewPlugin alloc]initWithScanPlugin:self.meterScanPlugin scanViewPluginConfig:scanViewPluginConfig];
//Set ScanMode to ALAutoAnalogDigitalMeter
BOOL success = [self.meterScanPlugin setScanMode:ALAutoAnalogDigitalMeter error:&error];
if( !success ) {
// Something went wrong. The error object contains the error description
[[[UIAlertView alloc] initWithTitle:@"Set ScanMode Error"
message:error.debugDescription
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
//Add ScanView (Camera and Flashbutton)
CGRect frame = [[UIScreen mainScreen] applicationFrame];
frame = CGRectMake(frame.origin.x, frame.origin.y + self.navigationController.navigationBar.frame.size.height, frame.size.width, frame.size.height - self.navigationController.navigationBar.frame.size.height);
self.scanView = [[ALScanView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) scanViewPlugin:self.meterScanViewPlugin];
//Enable Zoom Gesture
[self.scanView enableZoomPinchGesture:YES];
//Adding the scanView
[self.view addSubview:self.scanView];
[self.scanView startCamera];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
/*
This is the place where we tell Anyline to start receiving and displaying images from the camera.
Success/error tells us if everything went fine.
*/
NSError *error = nil;
BOOL success = [self.meterScanViewPlugin startAndReturnError:&error];
if( !success ) {
// Something went wrong. The error object contains the error description
[QMUITips showError:@"Start Scanning Error"];
}
}
/*
Cancel scanning to allow the module to clean up
*/
- (void)viewWillDisappear:(BOOL)animated {
[self.meterScanViewPlugin stopAndReturnError:nil];
}
#pragma mark - ALMeterScanPluginDelegate methods
/*
The main delegate method Anyline uses to report its scanned codes
*/
- (void)anylineMeterScanPlugin:(ALMeterScanPlugin *)anylineMeterScanPlugin
didFindResult:(ALMeterResult *)scanResult {
NSLog(@"% @",scanResult);
QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"Cancel" style:QMUIAlertActionStyleCancel handler:NULL];
QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"The results" message:scanResult.result preferredStyle:QMUIAlertControllerStyleAlert];
[alertController addAction:action1];
[alertController showWithAnimated:YES];
}
@end
Copy the code