iOS:銀行卡號掃描SDK card.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];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章