您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS:card.io 掃描銀行卡的完整接入步驟

編輯:iOS 開發綜合

專案裡有個需求:讓用戶掃一下銀行卡就自動帶入卡號。相比讓用戶手打十六位數字,掃描的體驗與準確率都更好。評估之後選用了 card.io——它調用手機攝像頭,藉助 OCR(光學字元識別)技術取得卡片資訊,並提供 SDK 供開發者集成。

步驟一:下載 SDK

可從 PayPal 官方倉庫取得最新版本:https://github.com/paypal/PayPal-iOS-SDK

步驟二:加入專案

1. 拖入 CardIO 文件夾,並在 TARGETS → Build Phases → Link Binary With Libraries 中加入依賴庫:

* AudioToolbox
* AVFoundation
* CoreGraphics
* CoreMedia
* CoreVideo
* Foundation
* MobileCoreServices
* OpenGLES
* QuartzCore
* Security
* UIKit

若使用 Xcode 5 或更新版本,只需要這幾個:

* AVFoundation
* AudioToolbox
* CoreMedia
* MobileCoreServices

2. 確認 Build Settings 中以下兩項為 YES:

* Enable Modules (C and Objective-C)
* Link Frameworks Automatically

3. 在 TARGETS → Build Settings 的 Other Linker Flags 中加入 -lc++。

步驟三:使用

我把 CardIOPaymentViewController 當作一個普通的 view controller 來用,以模態方式彈出。

#import "CardIO.h"
#import "CardIOPaymentViewControllerDelegate.h"

預先加載資源可以讓第一次打開掃描頁更快:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [CardIOUtilities preload];
}

啟動掃描:

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

兩個代理方法分別處理取消與完成:

// 用戶取消掃描
- (void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)scanViewController {
    NSLog(@"User canceled payment info");
    [scanViewController dismissViewControllerAnimated:YES completion:nil];
}

// 掃描完成
- (void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)info
            inPaymentViewController:(CardIOPaymentViewController *)scanViewController {
    NSLog(@"Received card info. Number: %@, expiry: %02i/%i, cvv: %@.",
          info.redactedCardNumber, info.expiryMonth, info.expiryYear, info.cvv);

    // 在這裡使用 info 的資料
    [scanViewController dismissViewControllerAnimated:YES completion:nil];
}

實務注意事項

  • 隱私與合規。 卡片資料屬於敏感資訊,card.io 提供 redactedCardNumber 讓你只取遮罩後的卡號;CVV 依支付產業規範通常不應由商家留存,接入前請先確認自身業務是否需要,以及是否符合相關規範。
  • 不要自行記錄。 除非確有必要,掃描結果應只用於當次交易,不寫入日誌、不上報統計。
  • 可客製化程度。 CardIOPaymentViewController 支援隱藏 CVV、有效期欄位,也能調整掃描框提示文案,依實際欄位需求調整即可。
  • 權限說明。 首次使用會請求攝像權限,記得在 Info.plist 補上 NSCameraUsageDescription 並寫清楚用途,否則會直接崩潰。
  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved