iOS - Card Identification 银行卡号识别
2016-09-15 07:28
1841 查看
1、CardIO 识别
框架 GitHub 下载地址配置
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、在我们需要调用的文件中导入
// 导入头文件 #import "CardIO.h" #import "CardIOPaymentViewControllerDelegate.h // 遵守协议 <CardIOPaymentViewControllerDelegate>
开始扫描银行卡
[CardIOUtilities preload]; CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self]; [self presentViewController:scanViewController animated:YES completion:nil];
取消扫描
// CardIOPaymentViewControllerDelegate 协议方法 - (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController { [[[UIAlertView alloc] initWithTitle:@"User cancelled sca" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show]; [self dismissViewControllerAnimated:YES completion:nil]; }
扫描完成
// CardIOPaymentViewControllerDelegate 协议方法 - (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentViewController:(CardIOPaymentViewController *)paymentViewController { // 获取扫描结果 // cardNumber 是扫描的银行卡号,显示的是完整号码,而 redactedCardNumber 只显示银行卡后四位,前面的用 * 代替了,返回的银行卡号都没有空格 NSString *redactedCardNumber = cardInfo.cardNumber; // 卡号 NSUInteger expiryMonth = cardInfo.expiryMonth; // 月 NSUInteger expiryYear = cardInfo.expiryYear; // 年 NSString *cvv = cardInfo.cvv; // CVV 码 // 显示扫描结果 NSString *msg = [NSString stringWithFormat:@"Number: %@\n\n expiry: %02lu/%lu\n\n cvv: %@", [self dealCardNumber:redactedCardNumber], expiryMonth, expiryYear, cvv]; [[[UIAlertView alloc] initWithTitle:@"Received card info" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show]; [self dismissViewControllerAnimated:YES completion:nil]; }
// 对银行卡号进行每隔四位加空格处理,自定义方法 - (NSString *)dealCardNumber:(NSString *)cardNumber { NSString *strTem = [cardNumber stringByReplacingOccurrencesOfString:@" " withString:@""]; NSString *strTem2 = @""; if (strTem.length % 4 == 0) { NSUInteger 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 { NSUInteger 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]]; } } } return strTem2; }
效果
相关文章推荐
- iOS开发之银行卡号识别
- Android/iOS拍照扫描自动识别银行卡号SDK
- iOS 银行卡号识别
- iOS根据银行卡号识别银行
- iOS开发--使用UITextField自动格式化银行卡号
- iOS开发笔记--使用UITextField自动格式化银行卡号
- XEditText:带删除功能的EditText;可设置自动添加分隔符分割电话号码、银行卡号等;支持禁止Emoji表情符号输入;自定义右边显示图标作功能选项;仿iOS输入框风格
- iOS开发 银行卡号有效性问题Luhn算法
- iOS开发笔记--使用UITextField自动格式化银行卡号
- iOS开发笔记-根据银行卡号判断银行名称
- 银行卡号识别(三) --- 基于k最近邻的数字识别测
- ios-为银行卡号格式化 每隔四位添加一个空格
- iOS-根据银行卡号判断银行名称
- XZ_iOS之判断输入的是不是银行卡号
- ios 银行卡号或身份证号按一定的个数分开显示
- 关于银行卡号识别
- iOS:扫描银行卡识别卡号
- IOS 使用UITextField自动格式化银行卡号
- iOS--输入银行卡号的时候,对数字格式化,每四个数后面加个“-”
- IOS TextField 输入银行卡号格式化(每四位中间空一格)