▲点击上方“CocoaChina”关注即可免费学习 iOS 开发
作者:Bison
原文链接:http://www.jianshu.com/p/82f73c23a76a
最近由于公司需要一个扫描银行卡获取卡号的功能,网上找了很多相关的资料,完全扫描银行卡获取卡号信息的都是价格贵的不得了的,而且仅仅只是授权而已,在此咱退而求次,找到一个可以扫描信用卡的第三方框架,给大家伙分享一下,只能扫描信用卡......o.0。框架的名字叫CardIO
下载地址:https://github.com/AllLuckly/card.io-iOS-SDK
在这里主要给大家演示一下怎么集成的,各位看官可得注意咯!
我的xcode是7.1版本的,首先是把框架整个拉进自己的工程,然后在TARGETS---Build Phases---Link Binary With Libraries里边分别加入下面这几个框架
再在TARGETS---Build Settings---Other Linker Flags中添加-ObjC和-lc++
然后在我们需要调用的VC中导入头文件#import "CardIO.h"和#import "CardIOPaymentViewControllerDelegate.h"加上代理CardIOPaymentViewControllerDelegate
然后是实现的方法
OC版
- (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版
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)
}
}
到此就大功告成了,希望可以找到扫描银行卡比较好用的第三方。最终的效果,识别的非常准确哦
▼
小编推荐:[掘金]是一个高质量的技术社区,从 Swift 到 React Native,性能优化到动效源码,让你不错过 iOS 开发的每一个技术干货。长按图片二维码识别或者各大应用市场搜索「掘金」,技术干货尽在掌握中。
微信号:CocoaChinabbs
▲长按二维码“识别”关注即可免费学习 iOS 开发
月薪十万、出任CEO、赢娶白富美、走上人生巅峰不是梦
--------------------------------------
商务合作QQ:2408167315