关闭

[iOS]OCR光学识别信用卡

标签: OCR光学识别信用卡识别信用卡
221人阅读 评论(0) 收藏 举报
分类:

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

原文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)
}
}

到此,基本就完成了,尝试一下吧!!!

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:117134次
    • 积分:1666
    • 等级:
    • 排名:千里之外
    • 原创:58篇
    • 转载:18篇
    • 译文:0篇
    • 评论:13条
    最新评论