您的当前位置:首页正文

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

来源:华拓网

然后在我们需要调用的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)
    }  
}



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

最终的效果,识别的非常准确哦

backing.png

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