使用CocoaPods
pod 'CardIO'
或者Demo下载https://github.com/AllLuckly/card.io-iOS-SDK
Xcode版本: Xcode 7.2.1
导入如下所示的库
Accelerate.framework
MobileCoreServices.framework
CoreMedia.framework
AudioToolbox.framework
AVFoundation.framework
导入头文件
#import <CardIO.h>
#import <CardIOPaymentViewControllerDelegate.h>
实现部分:
// 需要签协议: CardIOPaymentViewControllerDelegate
- (void)click:(UIButton *)sender
{
CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
// 进行简单的设置
scanViewController.hideCardIOLogo = YES;
scanViewController.collectCVV = NO;
scanViewController.collectExpiry = NO;
[self presentViewController:scanViewController animated:YES completion:nil];
}
Delegate
//取消扫描
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)scanViewController
{
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}
//扫描完成
-(void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)scanViewController
{
//扫描结果
NSLog(@"Received card info. Number: %@, expiry: %02ld/%ld, cvv: %@.%@", info.cardNumber, (unsigned long)info.expiryMonth, (unsigned long)info.expiryYear, info.cvv);
// 这里可以自己进行一些处理
///
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}