NHN Cloud OCR operates in iOS 11.0 or higher.
The configuration of NHN Cloud OCR SDK for iOS is as follows.
Service | Cocoapods Pod Name | Framework | Dependency | Build Settings |
---|---|---|---|---|
OCR | NHNCloudOCR | NHNCloudOCR.framework | * Vision.framework * AVFoundation.framework |
|
Mandatory | NHNCloudCore NHNCloudCommon |
NHNCloudCore.framework NHNCloudCommon.framework |
OTHER_LDFLAGS = ( "-ObjC", "-lc++" ); |
platform :ios, '11.0'
use_frameworks!
target '{YOUR PROJECT TARGET NAME}' do
pod 'NHNCloudOCR'
end
Key : NSCameraUsageDescription
Value : [Camera Permission Request Message]
// Initialize
+ (void)initWithConfiguration:(NHNCloudOCRConfiguration *)configuration;
// Set Delegate
+ (void)setDelegate:(nullable id<NHNCloudCreditCardRecognizerDelegate>)delegate;
// Initialize and set Delegate
+ (void)initWithConfiguration:(NHNCloudOCRConfiguration *)configuration
delegate:(nullable id<NHNCloudCreditCardRecognizerDelegate>)delegate;
@protocol NHNCloudCreditCardRecognizerDelegate <NSObject>
- (void)didDetectCreditCardInfo:(nullable NHNCloudCreditCardInfo *)cardInfo error:(nullable NSError *)error;
@optional
- (void)didDetectSecurityEvent:(NHNCloudSecurityEvent)event;
@end
@interface NHNCloudOCR : NSObject
//..
+ (void)setDetectedImageReturn:(BOOL)enable;
+ (BOOL)isEnableDetectedImageReturn;
//..
@end
#import <NHNCloudOCR/NHNCloudOCR.h>
@interface ViewController () <NHNCloudCreditCardRecognizerDelegate>
@end
@implementation ViewController
- (void)initializeOCR {
// Initialize and set Delegate
NHNCloudOCRConfiguration *configuration = [NHNCloudOCRConfiguration configurationWithAppKey:@"{AppKey}" secret:@"{Secret}"];
// Set detected image return
[NHNCloudOCR setDetectedImageReturn:YES];
// Initialize
[NHNCloudOCR initWithConfiguration:configuration delegate:self];
}
// Return credit card recognition result
- (void)didDetectCreditCardInfo:(nullable NHNCloudCreditCardInfo *)cardInfo error:(nullable NSError *)error {
NSLog(@"didDetectCreditCardInfo : cardInfo : %@", cardInfo);
NSLog(@"didDetectCreditCardInfo : error : %@", error);
}
// Receive screen capture event
- (void)didDetectSecurityEvent:(NHNCloudSecurityEvent)event {
// Example of screen capture warning alert output
if (event == NHNCloudSecurityEventScreenshot || event == NHNCloudSecurityEventScreenRecordingOn) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"Capture is detected." preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}
// Example of blank screen output when recording video
if (event == NHNCloudSecurityEventScreenRecordingOn || event == NHNCloudSecurityEventScreenRecordingOff) {
if ([[UIScreen mainScreen] isCaptured] ) {
[[[UIApplication sharedApplication] windows] firstObject].hidden = YES;
} else {
[[[UIApplication sharedApplication] windows] firstObject].hidden = NO;
}
}
}
@end
* Create ViewController Class that contains NHNCloudCreditCardRecognizerViewController as Subclass.
* Add ViewController to Storyboard.
* In the added ViewController, configure the class created in Custom Class.
* Set ViewController Segue Event.
enableTestGuide
. @interface NHNCloudOCRConfiguration : NSObject
- (void)enableTestGuide;
@end
- (void)initializeOCR {
// Initialize and set Delegate
NHNCloudOCRConfiguration *configuration = [NHNCloudOCRConfiguration configurationWithAppKey:@"{AppKey}" secret:@"{Secret}" ];
[configuration enableTestGuide];
[NHNCloudOCR initWithConfiguration:configuration delegate:self];
}
// Output CreditCard Recognizer ViewController from the SDK.
+ (NHNCloudCreditCardRecognizerViewController *)openCreditCardRecognizerViewController;
// Return CreditCard Recognizer ViewController. The user can output it directly, or the object activated in the SDK can be returned.
+ (nullable NHNCloudCreditCardRecognizerViewController *)creditCardRecognizerViewController;
// Open Recognizer ViewController from the SDK
[NHNCloudOCR openCreditCardRecognizerViewController];
// Let developers open Recognizer ViewController the way they want as the Recognizer ViewController is returned from the SDK.
NHNCloudCreditCardRecognizerViewController *creditCardRecognizerViewController = [NHNCloudOCR creditCardRecognizerViewController];
[self presentViewController:creditCardRecognizerViewController animated:YES completion:nil];
- (void)dismissViewController;
- (void)closeButton:(id)sender {
[[NHNCloudOCR creditCardRecognizerViewController] dismissViewController];
}
- (void)startRunning;
- (void)stopRunning;
- (BOOL)isRunning;
- (void)openAndStart {
[NHNCloudOCR openCreditCardRecognizerViewController];
[[NHNCloudOCR creditCardRecognizerViewController] startRunning];
}
// Return the credit card recognition result
- (void)didDetectCreditCardInfo:(nullable NHNCloudCreditCardInfo *)cardInfo error:(nullable NSError *)error {
[[NHNCloudOCR creditCardRecognizerViewController] stopRunning];
}
@property (assign, nonatomic, readonly) CGRect creditCardGuide;
@property (assign, nonatomic, readonly) NHNCloudCreditCardOrientation creditCardGuideOrientation;
- (void)rotateCreditCardGuideOrientation;
typedef NS_ENUM(NSInteger, NHNCloudCreditCardOrientation) {
NHNCloudCreditCardOrientationPortrait = 0,
NHNCloudCreditCardOrientationLandscape = 1
};
- (void)rotateButtonAction:(UIButton *)button {
[[NHNCloudOCR creditCardRecognizerViewController] rotateCreditCardGuideOrientation];
NSLog(@"x: %f y: %f width: %f height: %f", [NHNCloudOCR creditCardRecognizerViewController].creditCardGuide.origin.x,
[NHNCloudOCR creditCardRecognizerViewController].creditCardGuide.origin.y,
[NHNCloudOCR creditCardRecognizerViewController].creditCardGuide.size.width,
[NHNCloudOCR creditCardRecognizerViewController].creditCardGuide.size.height);
NSLog(@"creditCardGuideOrientation: %ld", [NHNCloudOCR creditCardRecognizerViewController].creditCardGuideOrientation);
}
- (void)enableTorchMode;
- (void)disableTorchMode;
- (BOOL)isEnableTorchMode;
- (void)torchButtonAction:(UIButton *)button {
if ([[NHNCloudOCR creditCardRecognizerViewController] isEnableTorchMode] == YES) {
[[NHNCloudOCR creditCardRecognizerViewController] disableTorchMode];
} else {
[[NHNCloudOCR creditCardRecognizerViewController] enableTorchMode];
}
}
- (void)startRunningCamera;
- (void)stopRunningCamera;
- (BOOL)isRunnginCamera;
- (void)cameraButtonAction:(UIButton *)button {
if ([[NHNCloudOCR creditCardRecognizerViewController] isRunnginCamera] == YES) {
[[NHNCloudOCR creditCardRecognizerViewController] stopRunningCamera];
} else {
[[NHNCloudOCR creditCardRecognizerViewController] startRunningCamera];
}
}
- (void)viewDidLoad;
- (void)viewWillAppear:(BOOL)animated;
- (void)viewWillDisappear:(BOOL)animated;
- (void)viewDidDisappear:(BOOL)animated;
- (void)didUpdateCreditCardGuide:(CGRect)rect orientation:(NHNCloudCreditCardOrientation)orientation;
- (void)imageDidDetect:(BOOL)detected;
@interface OCRViewController : NHNCloudCreditCardRecognizerServiceViewController <NHNCloudCreditCardRecognizerDelegate>
@end
@implementation OCRViewController
- (void)viewDidLoad {
[super viewDidLoad];
[NHNCloudOCR setDelegate:self];
// Create Custom UI
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self startRunning];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
- (void)didUpdateCreditCardGuide:(CGRect)rect orientation:(NHNCloudCreditCardOrientation)orientation {
[super didUpdateCreditCardGuide:rect orientation:orientation];
// Update Custom UI
}
- (void)imageDidDetect:(BOOL)detected {
[super imageDidDetect:detected];
// Update UI for credit card recognition
}
- (void)didDetectCreditCardInfo:(nullable NHNCloudCreditCardInfo *)cardInfo error:(nullable NSError *)error {
NSLog(@"didDetectCreditCardInfo : cardInfo : %@", cardInfo);
NSLog(@"didDetectCreditCardInfo : error : %@", error);
}