NHN Cloud OCRはiOS 11.0以上で動作します。
iOS用NHN Cloud OCR SDKの構成は次のとおりです。
Service | Cocoapods Pod Name | Framework | Dependency | Build Settings |
---|---|---|---|---|
IAP | 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);
}