前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS开发之OCR光学识别储蓄卡以及信用卡

iOS开发之OCR光学识别储蓄卡以及信用卡

作者头像
Bison
发布2018-06-28 17:46:27
1.6K0
发布2018-06-28 17:46:27
举报
文章被收录于专栏:iOS Developer

最近由于公司需要一个扫描银行卡获取卡号的功能,网上找了很多相关的资料,完全扫描银行卡 获取卡号信息的都是价格贵的不得了的,而且仅仅只是授权而已,在此咱退而求次,找到一个可 以扫描信用卡的第三方框架,给大家伙分享一下,只能扫描信用卡......o.0。 框架的名字叫CardIO 下载地址 在这里主要给大家演示一下怎么集成的,各位看官可得注意咯! 我的xcode是7.1版本的,首先是把框架整个拉进自己的工程,然后在 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++

然后在我们需要调用的VC中导入头文件#import "CardIO.h"#import "CardIOPaymentViewControllerDelegate.h" 加上代理CardIOPaymentViewControllerDelegate

然后是实现的方法

OC版

代码语言:javascript
复制
- (void)viewDidLoad {
    [super viewDidLoad];

    [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版

代码语言:javascript
复制
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)
    }  
}

到此就大功告成了,老外封装的东西还是非常给力的,希望可以找到扫描银行卡比较好用的第三方。 最终的效果,识别的非常准确哦

backing.png

推荐一款学习iOS开发的app_____|______| | 传送门

更多经验请点击 技术交流群:534926022(免费) 511040024(0.8/人付费) 好文推荐:iOS开发内购全套图文教程

版权归©Bison所有 如需转载请保留原文超链接地址!否则后果自负!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015.12.11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • OC版
  • SWIFT版
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档