iOS開發之OCR光學識別儲蓄卡以及信用卡

來源:互聯網
上載者:User

標籤:

最近由於公司需要一個掃描銀行卡擷取卡號的功能,網上找了很多相關的資料,完全掃描銀行卡擷取卡號資訊的都是價格貴的不得了的,而且僅僅只是授權而已,在此咱退而求次,找到一個可以掃描信用卡的第三方架構,給大傢伙分享一下,只能掃描信用卡……o.0。

 

架構的名字叫CardIO

 

  • https://github.com/AllLuckly/card.io-iOS-SDK

 

在這裡主要給大家示範一下怎麼整合的,各位看官可得注意咯!我的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版

 

- (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: %<a href="http://www.jobbole.com/members/uz441800">@,</a> 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)

    }  

}

 

到此就大功告成了,老外封裝的東西還是非常給力的,希望可以找到掃描銀行卡比較好用的第三方。

最終的效果,識別的非常準確哦

 

iOS開發之OCR光學識別儲蓄卡以及信用卡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.