NHN Cloud OCR은 iOS 11.0 이상에서 동작합니다.
iOS용 NHN Cloud OCR SDK의 구성은 다음과 같습니다.
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 : [카메라 권한 요청 메세지]
// 초기화
+ (void)initWithConfiguration:(NHNCloudOCRConfiguration *)configuration;
// Delegate 설정
+ (void)setDelegate:(nullable id<NHNCloudCreditCardRecognizerDelegate>)delegate;
// 초기화 및 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 {
// 초기화 및 Delegate 설정
NHNCloudOCRConfiguration *configuration = [NHNCloudOCRConfiguration configurationWithAppKey:@"{AppKey}" secret:@"{Secret}"];
// 검출 이미지 반환 설정
[NHNCloudOCR setDetectedImageReturn:YES];
// 초기화
[NHNCloudOCR initWithConfiguration:configuration delegate:self];
}
// 신용카드 인식 결과 반환
- (void)didDetectCreditCardInfo:(nullable NHNCloudCreditCardInfo *)cardInfo error:(nullable NSError *)error {
NSLog(@"didDetectCreditCardInfo : cardInfo : %@", cardInfo);
NSLog(@"didDetectCreditCardInfo : error : %@", error);
}
// 스크린 캡처 이벤트 수신
- (void)didDetectSecurityEvent:(NHNCloudSecurityEvent)event {
// 스크린 캡처 경고 Alert 출력 예시
if (event == NHNCloudSecurityEventScreenshot || event == NHNCloudSecurityEventScreenRecordingOn) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"캡쳐가 감지되었습니다." preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];
}
// 동영상 녹화 시 빈 화면 출력 예시
if (event == NHNCloudSecurityEventScreenRecordingOn || event == NHNCloudSecurityEventScreenRecordingOff) {
if ([[UIScreen mainScreen] isCaptured] ) {
[[[UIApplication sharedApplication] windows] firstObject].hidden = YES;
} else {
[[[UIApplication sharedApplication] windows] firstObject].hidden = NO;
}
}
}
@end
* NHNCloudCreditCardRecognizerViewController를 subclass로 가지는 ViewController Class를 생성합니다.
* Storyboard에 ViewController를 추가합니다.
* 추가한 ViewController에 Custom Class에 생성한 Class를 설정합니다.
* ViewController Segue Event를 설정합니다.
enableTestGuide
를 사용하여 테스트용 가이드를 출력할 수 있습니다. @interface NHNCloudOCRConfiguration : NSObject
- (void)enableTestGuide;
@end
- (void)initializeOCR {
// 초기화 및 Delegate 설정
NHNCloudOCRConfiguration *configuration = [NHNCloudOCRConfiguration configurationWithAppKey:@"{AppKey}" secret:@"{Secret}" ];
[configuration enableTestGuide];
[NHNCloudOCR initWithConfiguration:configuration delegate:self];
}
// CreditCard Recognizer ViewController을 SDK에서 출력합니다.
+ (NHNCloudCreditCardRecognizerViewController *)openCreditCardRecognizerViewController;
// CreditCard Recognizer ViewController을 반환합니다. 사용자가 직접 출력하거나 SDK에 활성화된 객체를 반환 받을 수 있습니다.
+ (nullable NHNCloudCreditCardRecognizerViewController *)creditCardRecognizerViewController;
// SDK에서 Recognizer ViewController를 열게 합니다.
[NHNCloudOCR openCreditCardRecognizerViewController];
// SDK에서 Recognizer ViewController를 반환받아 개발자가 원하는 방법으로 직접 열게 합니다.
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];
}
// 신용카드 인식 결과 반환
- (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];
// 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];
// Custom UI 갱신
}
- (void)imageDidDetect:(BOOL)detected {
[super imageDidDetect:detected];
// 신용카드 인식 시 UI 갱신
}
- (void)didDetectCreditCardInfo:(nullable NHNCloudCreditCardInfo *)cardInfo error:(nullable NSError *)error {
NSLog(@"didDetectCreditCardInfo : cardInfo : %@", cardInfo);
NSLog(@"didDetectCreditCardInfo : error : %@", error);
}