最近由于公司需要一個(gè)掃描銀行卡獲取卡號(hào)的功能叔遂,網(wǎng)上找了很多相關(guān)的資料咏连,完全掃描銀行卡
獲取卡號(hào)信息的都是價(jià)格貴的不得了的诫舅,而且僅僅只是授權(quán)而已笛辟,在此咱退而求次功氨,找到一個(gè)可
以掃描信用卡的第三方框架,給大家伙分享一下手幢,只能掃描信用卡......o.0捷凄。
框架的名字叫CardIO
下載地址
在這里主要給大家演示一下怎么集成的,各位看官可得注意咯围来!
我的xcode是7.1版本的跺涤,首先是把框架整個(gè)拉進(jìn)自己的工程,然后在
TARGETS---Build Phases---Link Binary With Libraries
里邊分別加入下面這幾個(gè)框架
Accelerate.framework
MobileCoreServices.framework
CoreMedia.framework
AudioToolbox.framework
AVFoundation.framework
再在TARGETS---Build Settings---Other Linker Flags中添加-ObjC
和-lc++
然后在我們需要調(diào)用的VC
中導(dǎo)入頭文件#import "CardIO.h"
和#import "CardIOPaymentViewControllerDelegate.h"
加上代理CardIOPaymentViewControllerDelegate
然后是實(shí)現(xiàn)的方法
OC版
- (void)viewDidLoad {
[super viewDidLoad];
[CardIOUtilities preload];
}
//開(kāi)始調(diào)用掃描
- (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
{
//掃描結(jié)果
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()
}
//開(kāi)始調(diào)用掃描
@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)
}
}
到此就大功告成了监透,老外封裝的東西還是非常給力的桶错,希望可以找到掃描銀行卡比較好用的第三方。
最終的效果胀蛮,識(shí)別的非常準(zhǔn)確哦
更多經(jīng)驗(yàn)請(qǐng)點(diǎn)擊
技術(shù)交流群:534926022(免費(fèi)) 511040024(0.8/人付費(fèi))
好文推薦:iOS開(kāi)發(fā)內(nèi)購(gòu)全套圖文教程
版權(quán)歸?Bison所有 如需轉(zhuǎn)載請(qǐng)保留原文超鏈接地址院刁!否則后果自負(fù)!