银行卡扫描(基于swift)

①下载CardIO库

②将库文件解压,拖入工程,务必按下图勾选

③选中项目,target-->build Setting-->All    Other Linker Flags
    双击“+”,添加语句“-lc++”
④General,找到Linked Frameworks and libtaries
  添加库:
  AVFoundation
  AudioToolbox
  CoreMedia
  MobileCoreServices
  libCardIO.a
⑤CardScanner-->newfile-->Objective-c-->file-->CardBridgingHeader-->Finish-->Yes
  将.m文件删除
  在.h中# import "CardIO.h"
⑥Storyboard中
  1, 拖控件一个button和一个label分别创建button的方法和label的属性
  2,继承协议CardIOPaymentViewControllerDelegate并实现协议里的两个方法
    //用户取消扫描
      func userDidCancelPaymentViewController(paymentViewController: CardIOPaymentViewController!) {
          result.text = "Scan cancel"
          //关闭窗口
          paymentViewController.dismissViewControllerAnimated(true, completion: nil)
      }
      //用户确认扫描
      func userDidProvideCreditCardInfo(cardInfo: CardIOCreditCardInfo!, inPaymentViewController paymentViewController: CardIOPaymentViewController!) {
          if let card = cardInfo{
              result.text = "卡号:\(card.cardNumber)\n过期年月:\(card.expiryYear)年\(card.expiryMonth)月\nCVV:\(card.cvv)"
          }
          paymentViewController.dismissViewControllerAnimated(true, completion: nil)
      }
  3,扫描按键的方法    
    @IBAction func startsacn(sender: AnyObject) {
         let cardvc = CardIOPaymentViewController(paymentDelegate: self)
          cardvc.modalPresentationStyle = UIModalPresentationStyle.FormSheet
          presentViewController(cardvc, animated: true, completion: nil)
      }
  4,真机调试可能会报错,关闭bitcode
    项目-->Build Setting-->All -->Enable Bitcode-->No

posted on 2015-12-14 11:27  罗小夕  阅读(652)  评论(0编辑  收藏  举报

导航