iOS:card.io使用,ioscard.io使用
最近項目要用到一個功能:通過掃描銀行卡,擷取銀行卡號,在網上搜過後,選用了card.io這個SDK,過程如下:
(1)下載Card.io
Card.io是讓手機網路攝影機擷取信用卡的資訊,中間利用了OCR(光學字元辨識)的掃描技術返回結果,它還推出了SDK(軟體開發包),讓開發人員們可以把card.io添加到自己的應用當中。可以在https://github.com/paypal/PayPal-iOS-SDK下載最新的SDK或者直接下載我的下載好的:http://download.csdn.net/detail/u012890196/8658627
(2)添加到項目裡
1、將下載的SDK包裡名為CardIO的檔案拖到工程裡,在TARGETS-Build Phases - Link Binary With Librarys添加下面依賴庫
* AudioToolbox
* AVFoundation
* CoreGraphics
* CoreMedia
* CoreVideo
* Foundation
* MobileCoreServices
* OpenGLES
* QuartzCore
* Security
* UIKit
如果是xcode5或者更新的版本,只需要添加下面的庫
* 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"#import "CardIOPaymentViewControllerDelegate.h"- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [CardIOUtilities preload];}//開始掃描- (IBAction)scanCard:(id)sender { CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self]; [self presentViewController:scanViewController animated:YES completion:nil];}下面是代理方法//取消掃描- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)scanViewController { NSLog(@"User canceled payment info"); // Handle user cancellation here... [scanViewController dismissViewControllerAnimated:YES completion:nil];}//掃描完成-(void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)scanViewController { //掃描結果//CardIOCreditCardInfo *info裡麵包含了銀行卡的一些資訊,如info.cardNumber是掃描的銀行卡號,現實的是完整號碼,而info.redactedCardNumber只顯示銀行卡後四位,前面的用*代替了,返回的銀行卡號都沒有空格可以用下面注釋的方法來加空格// NSString *strTem = [info.cardNumber stringByReplacingOccurrencesOfString:@" " withString:@""];// NSString *strTem2 = @"";// if (strTem.length % 4 == 0)// {// int count = strTem.length / 4;// for (int i = 0; i < count; i++)// {// NSString *str = [strTem substringWithRange:NSMakeRange(i * 4, 4)];// strTem2 = [strTem2 stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];// }// }// else// {// int count = strTem.length / 4;// for (int j = 0; j <= count; j++)// {// if (j == count)// {// NSString *str = [strTem substringWithRange:NSMakeRange(j * 4, strTem.length % 4)];// strTem2 = [strTem2 stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];// }// else// {// NSString *str = [strTem substringWithRange:NSMakeRange(j * 4, 4)];// strTem2 = [strTem2 stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];// }// }// } NSLog(@"Received card info. Number: %@, expiry: %02i/%i, cvv: %@.", info.redactedCardNumber, info.expiryMonth, info.expiryYear, info.cvv); // Use the card info... [scanViewController dismissViewControllerAnimated:YES completion:nil];}