下载地址:https://github.com/AllLuckly/card.io-iOS-SDK
首先是把框架整个拉进自己的工程,然后在
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
代码实现:
//
// ViewController.m
// 扫描银行卡识别卡号
//
// Created by 张士玉 on 16/7/13.
// Copyright © 2016年 张士玉. All rights reserved.
//
#import "ViewController.h"
#import "CardIO.h"
#import "CardIOPaymentViewControllerDelegate.h"
@interface ViewController ()<CardIOPaymentViewControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[CardIOUtilities preload];
}
//开始调用扫描
- (IBAction)begin:(id)sender {
CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
[self presentViewController:scanViewController animated:YES completion:nil];
}
//取消扫描
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
[paymentViewController dismissViewControllerAnimated:YES completion:nil];
}
//扫描完成
- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
//扫描结果
NSLog(@"Received card info. Number: %@, expiry: %02lu/%lu, cvv: %@.", cardInfo.redactedCardNumber, (unsigned long)cardInfo.expiryMonth, (unsigned long)cardInfo.expiryYear, cardInfo.cvv);
NSString *no = cardInfo.cardNumber;
NSLog(@"%@", no);
[paymentViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end