您的位置:首页 > 移动开发 > IOS开发

[iOS]OCR光学识别信用卡

2016-08-28 17:00 871 查看
看到一个光学识别信用卡的文章,根据文章测试了下,识别信用卡还算灵敏,但是可惜的是识别不了储蓄卡,这里记录一下:

原文cocoachina微信公共号链接

所用框架github地址:https://github.com/AllLuckly/card.io-iOS-SDK

具体的使用,demo中有介绍,这里只记录一下集成:

将demo里的CardIO文件夹拖进工程,然后在TARGETS---Build Phases---Link Binary
With Libraries里边加入系统框架框架:

Accelerate.framework
MobileCoreServices.framework
CoreMedia.framework
AudioToolbox.framework
AVFoundation.framework
最后,在TARGETS---Build Settings---Other Linker Flags中添加-ObjC和-lc++即可;

接下来就可以使用相关的API了:

首先导入头文件:

#import "CardIO.h"
#import "CardIOPaymentViewControllerDelegate.h"

并实现代理CardIOPaymentViewControllerDelegate

实现代理方法:

Objective-C:

(void)viewWillAppear {
[super viewWillAppear];
[CardIOUtilities preload];
}
//开始调用扫描
- (IBAction)begin:(id)sender {
CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
[self presentViewController:scanViewController animated:YES completion:nil];
}
//取消扫描
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)scanViewController
{
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}
//扫描完成
-(void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)scanViewController
{
//扫描结果
NSLog(@"Received card info. Number: %@, expiry: %02i/%i, cvv: %@.", info.redactedCardNumber, info.expiryMonth, info.expiryYear, info.cvv);
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}


Swift:

import UIKit
class ViewController: UIViewController, CardIOPaymentViewControllerDelegate {
@IBOutlet weak var resultLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
CardIOUtilities.preload()
}
//开始调用扫描
@IBAction func scanCard(sender: AnyObject) {
let cardIOVC = CardIOPaymentViewController(paymentDelegate: self)
cardIOVC.modalPresentationStyle = .FormSheet
presentViewController(cardIOVC, animated: true, completion: nil)
}
//取消扫描
func userDidCancelPaymentViewController(paymentViewController: CardIOPaymentViewController!) {
resultLabel.text = "user canceled"
paymentViewController?.dismissViewControllerAnimated(true, completion: nil)
}
//扫描完成
func userDidProvideCreditCardInfo(cardInfo: CardIOCreditCardInfo!, inPaymentViewController paymentViewController: CardIOPaymentViewController!) {
if let info = cardInfo {
let str = NSString(format: "Received card info.\\\\n Number: %@\\\\n expiry: %02lu/%lu\\\\n cvv: %@.", info.redactedCardNumber, info.expiryMonth, info.expiryYear, info.cvv)
resultLabel.text = str as String
}
paymentViewController?.dismissViewControllerAnimated(true, completion: nil)
}
}

到此,基本就完成了,尝试一下吧!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息