Skip to main content
Version: 2.4.0

Base Implementation

Start to scan

Objc

//Create the SmartScanner object reference
SmartScanner* sc;

//Init SmartScanner when needed, and set the delegate
sc = [[SmartScanner alloc] init];
sc.scDelegate = self;

//Retrieve the preview screen and display it on your view
UIView* preview = [sc previewViewWithViewSize:self.view.bounds];
[self.view addSubview:preview];
[sc setDecodingType: SmartDecodingTypes andSubType: SmartDecodingSubtimes];

//Eventually set a custom ROI (This must be done after setting the decoding type)
[sc setRegionOfInterest:CGRectMake(0, 0, 300, 300)] ;
//For some types of OCR the camera orientation should be specified
[sc setDecodingOrientation:[UIApplication sharedApplication].statusBarOrientation ];

Swift

//Instanciate the scanner
let scan = SmartScanner()
//Create a view and use it like a standard UIView
let preview = scan.previewView(withViewSize: self.view.bounds)
scan.scDelegate = self
self.view.insertSubview(preview!, at: 0)

//Set the type of code to decode
scan.setDecodingType(CODE_EU_PLATES.rawValue andSubType: CODE_PLT_CHE.rawValue)

//For some types of OCR the camera orientation should be specified
scan.setDecoding(UIApplication.shared.statusBarOrientation)

//Customize your ROI if needed, this need to be done after setting the type of code
let regionOfInterest = CGRect(x: 0.0, y: 0.0, width: 160, height: 160)
scan.setRegionOfInterest(regionOfInterest)

Select the type of code you want to decode

You can use a combination of any type or subtype that is enabled in the version you have. At any point you can set another decoding type (Verify the enabled types of your SmartScan version by calling the version function).

Thoses are referenced in the enums

SmartDecodingSubTypes
SmartDecodingTypes

For example

objc

#define TypeToDecode    (CODE_OCRB  | CODE_EU_PLATES )
#define SubTypeToDecode (CODE_PLT_ALL | CODE_ICAO_9303_PASSPORT | CODE_ICAO_9303_IDCARD | CODE_FRENCH_IDS | CODE_ROMANIAN_IDS | CODE_ROMANIAN_IDS | CODE_ROMANIAN_IDS)
[sc setDecodingType: TypeToDecode andSubType: SubTypeToDecode];

swift

//Use the rawValue of the enums
var typeOfCode : UInt64 = CODE_OCRB.rawValue
var subtypeOfCode : UInt64 = CODE_BVR.rawValue | CODE_ICAO_9303_IDCARD.rawValue

//Configuring what type of content to scan.
scan.setDecodingType(typeOfCode, andSubType: subtypeOfCode)

included in IcareDecodersCodes.h

Retrieve the results by implementing the delegate protocol

objc

- (void)SmartScan:(SmartScanner *)smartScanner foundResult:(SmartScanResult *)smartScannerResult
{
NSString* message = [NSString stringWithFormat:@"Smartscan : %@ with type : %@", smartScannerResult.content, smartScannerResult.codeDescription];
NSLog(@"%@", message);

}

swift

func smartScan(_ smartScanner: SmartScanner, found smartScannerResult: SmartScanResult) {
print("Result : \(smartScannerResult.content) type : \(smartScannerResult.codeDescription)")
}

Release the resources when you don't need to use the smartscanner anymore

objc

[sc closeCameraStream];
sc = nil;

swift

sc?.closeCameraStream()
sc = nil