扫描银行卡,获取银行卡号 - Card.io

实现功能:通过扫描银行卡,获取银行卡号。

在网上搜过后,选用了card.io这个SDK,其他的都要收费,不过这个sdk只能扫描有凸起的银行卡,平面字体无法识别。

过程如下:

(1)下载Card.io

Card.io是让手机摄像头获取信用卡的信息,中间利用了OCR(光学字符识别)的扫描技术返回结果,它还推出了SDK(软件开发包),让开发者们可以把card.io添加到自己的应用当中。可以在https://github.com/paypal/PayPal-iOS-SDK下载最新的SDK

(2)添加到项目里

1、将下载的SDK包里名为CardIO的文件拖到工程里,在TARGETS-Build Phases - Link Binary With Librarys添加下面依赖库
* Accelerate
* AVFoundation
* AudioToolbox
* CoreMedia
* MobileCoreServices

并且保证Build Settings里面这两项都是YES:
- Enable Modules (C and Objective-C)
- Link Frameworks Automatically

2、在TARGETS-Build Settings添加 -lc++到Other Linker Flags

(3)使用
我是把它作为一个viewController类使用

导入 #import “CardIO.h”

遵循协议CardIOPaymentViewControllerDelegate

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [CardIOUtilities preload];
}

- (void)scanButtonAction{
    CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
    scanViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:scanViewController animated:YES completion:nil];
}

pragma mark - CardIOPaymentViewControllerDelegate

//扫描完成

- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
    NSLog(@"Scan succeeded with info: %@", info);
// Do whatever needs to be done to deliver the purchased items.
    [self dismissViewControllerAnimated:YEScompletion:nil];
    self.infoLabel.text = info.cardNumber;
    NSString *infoText = [NSStringstringWithFormat:@"Received card info. Number: %@, expiry: %02lu/%lu, cvv: %@.", info.redactedCardNumber, (unsignedlong)info.expiryMonth, (unsignedlong)info.expiryYear, info.cvv];
    NSLog(@"%@", infoText);
}

//用户取消扫描

- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
    NSLog(@"User cancelled scan");
    [self dismissViewControllerAnimated:YEScompletion:nil];
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值