銀行卡號自動識別


1、CardIO識別

1.1 、CaedIO SDK下載

下載地址

1.2、使用方法

1、把框架整個拉進自己的工程,然后在 TARGETS => Build Phases => Link Binary With Libraries 里邊分別加入下面這幾個框架。

Accelerate.framework
MobileCoreServices.framework
CoreMedia.framework
AudioToolbox.framework
AVFoundation.framework

2、在TARGETS => Build Settings => Other Linker Flags 中添加 -ObjC 和 -lc++ 。

3、在 iOS8 + 系統中使用相機需要在 Info.plist 中添加 Privacy - Camera Usage Description,並設置其值。

4、在我們需要調用的文件中導入

1  // 導入頭文件
2 #import "CardIO.h"
3 #import "CardIOPaymentViewControllerDelegate.h
4 
5 // 遵守協議
6 <CardIOPaymentViewControllerDelegate>

1.3、主要方法

1、開始掃描銀行卡

1 [CardIOUtilities preload];
2 
3 CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
4 
5 [self presentViewController:scanViewController animated:YES completion:nil];

2、取消掃描

 1 // CardIOPaymentViewControllerDelegate 協議方法
 2 - (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
 3 
 4 [[[UIAlertView alloc] initWithTitle:@"User cancelled sca" 
 5                                     message:nil  
 6                                    delegate:nil 
 7                           cancelButtonTitle:@"確定" otherButtonTitles:nil, nil] show];
 8 
 9 [self dismissViewControllerAnimated:YES completion:nil];
10 }

3、完成掃描

 1  // CardIOPaymentViewControllerDelegate 協議方法
 2     - (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
 3 
 4         // 獲取掃描結果
 5 
 6         // cardNumber 是掃描的銀行卡號,顯示的是完整號碼,而 redactedCardNumber 只顯示銀行卡后四位,前面的用 * 代替了,返回的銀行卡號都沒有空格
 7 
 8         NSString *redactedCardNumber = cardInfo.cardNumber;     // 卡號
 9         NSUInteger expiryMonth = cardInfo.expiryMonth;          //
10         NSUInteger expiryYear = cardInfo.expiryYear;            //
11         NSString *cvv = cardInfo.cvv;                           // CVV 碼
12 
13         // 顯示掃描結果
14         NSString *msg = [NSString stringWithFormat:@"Number: %@\n\n expiry: %02lu/%lu\n\n cvv: %@", [self dealCardNumber:redactedCardNumber], expiryMonth, expiryYear, cvv];
15         [[[UIAlertView alloc] initWithTitle:@"Received card info" message:msg  delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil] show];
16 
17         [self dismissViewControllerAnimated:YES completion:nil];
18     }

4、銀行卡信息處理

 1 // 對銀行卡號進行每隔四位加空格處理,自定義方法
 2     - (NSString *)dealCardNumber:(NSString *)cardNumber {
 3 
 4         NSString *strTem = [cardNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
 5         NSString *strTem2 = @"";
 6 
 7         if (strTem.length % 4 == 0) {
 8 
 9             NSUInteger count = strTem.length / 4;
10             for (int i = 0; i < count; i++) {
11                 NSString *str = [strTem substringWithRange:NSMakeRange(i * 4, 4)];
12                 strTem2 = [strTem2 stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];
13             }
14 
15         } else {
16 
17             NSUInteger count = strTem.length / 4;
18             for (int j = 0; j <= count; j++) {
19 
20                 if (j == count) {
21                     NSString *str = [strTem substringWithRange:NSMakeRange(j * 4, strTem.length % 4)];
22                     strTem2 = [strTem2 stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];
23                 } else {
24                     NSString *str = [strTem substringWithRange:NSMakeRange(j * 4, 4)];
25                     strTem2 = [strTem2 stringByAppendingString:[NSString stringWithFormat:@"%@ ", str]];
26                 }
27             }
28         }
29 
30         return strTem2;
31     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM