IOS 之扫描银行卡号DEMO

通过扫描银行卡,获取银行卡号,在网上搜过后,选用了card.io这个SDK,过程如下:

(1)下载Card.io

Card.io是让手机摄像头获取信用卡的信息,中间利用了OCR(光学字符识别)的扫描技术返回结果,它还推出了SDK(软件开发包),让开发者们可以把card.io添加到自己的应用当中。可以在https://github.com/paypal/PayPal-iOS-SDK下载最新的SDK

(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
    *
    代码说明:
    开始触发扫描

- (IBAction)BeginActionCardID:(id)sender {
    CardIOPaymentViewController *scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
    scanViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:scanViewController animated:YES completion:nil];
}

代理方法

#pragma mark - CardIOPaymentViewControllerDelegate
//扫描完成
- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info inPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
    NSLog(@"Scan succeeded with info: %@", info);
    // Do whatever needs to be done to deliver the purchased items.
    [self dismissViewControllerAnimated:YES completion:nil];

    self.infoLabel.text = [NSString stringWithFormat:@"Received card info. Number: %@, expiry: %02lu/%lu, cvv: %@.", info.redactedCardNumber, (unsigned long)info.expiryMonth, (unsigned long)info.expiryYear, info.cvv];
}
//用户取消扫描
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController {
    NSLog(@"User cancelled scan");
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [CardIOUtilities preload];
}

遇到的问题解决方法:
1、遇到很多的错误,但是大多数都是没有导入依赖库,但是当全部导入依赖库后,还是会报错,而且错误达到了20多个,这个就得需要设置了,看下列解决方案。
IOS 之扫描银行卡号DEMO_第1张图片

这么多看着就是揪心的,下面就是解决方法。

在TARGETS-Build Settings添加 -lc++ 到Other Linker Flags

IOS 之扫描银行卡号DEMO_第2张图片

2、问题解决了,但是会在点击调用相机的时候会崩溃,又得解决问题;
下面是打印的奔溃日志:
IOS 之扫描银行卡号DEMO_第3张图片
从奔溃日志里面可以看到解决的方法;
IOS 之扫描银行卡号DEMO_第4张图片

在TARGETS-Build Settings添加 -ObjC 到Other Linker Flags

就这样就ok了

你可能感兴趣的:(IOS基础实例,OC基础,UI,iOS打包上线错误,服务器)