IOS: card. io usage, ioscard. io usage
Recently, a function is used to scan a bank card and obtain the bank card number. After searching the Internet, the SDK card. io is used. The process is as follows:
(1) download Card. io
Card. i/O allows the mobile phone camera to obtain credit card information, and uses OCR (Optical Character Recognition) Scanning Technology to return the results. It also introduces the SDK (software development kit ), let developers put the card. i/O is added to your own application. You can
(2) Add to project
1. Drag the downloaded CardIO file in the SDK package to the project and add the following dependent libraries in TARGETS-Build Phases-Link Binary With Librarys.
* AudioToolbox
* AVFoundation
* CoreGraphics
* CoreMedia
* CoreVideo
* Foundation
* MobileCoreServices
* OpenGLES
* QuartzCore
* Security
* UIKit
If it is xcode5 or an updated version, you only need to add the following Library
* AVFoundation
* AudioToolbox
* CoreMedia
* MobileCoreServices
Make sure that the two items in Build Settings are YES:
* Enable Modules (C and Objective-C)
* Link Frameworks Automatically
2. Add-lc ++ to Other Linker Flags in TARGETS-Build Settings.
(3) Use
I use it as a viewController class.
Code:
Import
# Import "CardIO. h "# import" CardIOPaymentViewControllerDelegate. h "-(void) viewWillAppear :( BOOL) animated {[super viewWillAppear: animated]; [CardIOUtilities preload];} // start scan-(IBAction) scanCard :( id) sender {CardIOPaymentViewController * scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate: self]; [self presentViewController: scanViewController animated: YES completion: nil];} the following is the proxy method // cancel scan-(void) userDidCancelPaymentViewController :( CardIOPaymentViewController *) scanViewController {NSLog (@ "User canceled payment info"); // Handle user cancellation here... [scanViewController dismissViewControllerAnimated: YES completion: nil];} // scan completed-(void) userDidProvideCreditCardInfo :( CardIOCreditCardInfo *) info inPaymentViewController :( CardIOPaymentViewController *) scanViewController {// scan result // CardIOCreditCardInfo * info contains some information about the bank card, such as info. cardNumber is the scanned bank card number, but the actual number is the complete number, and info. redactedCardNumber only displays the last four digits of the bank card. The preceding digits are replaced by "*". If no return bank card number is blank, you can add a space using the method described below. // NSString * strTem = [info. cardNumber stringByReplacingOccurrencesOfString: @ "" withString: @ ""]; // NSString * strTem2 = @ ""; // if (strTem. length % 4 = 0) // {// int count = strTem. length/4; // for (int I = 0; I <count; I ++) // {// NSString * str = [strTem substringWithRange: NSMakeRange (I * 4, 4)]; // strTem2 = [strTem2 stringByAppendingString: [NSString stringWithFormat: @ "% @", str]; ///} // else // {// int count = strTem. length/4; // for (int j = 0; j <= count; j ++) // {// if (j = count) // {// NSString * str = [strTem substringWithRange: NSMakeRange (j * 4, strTem. length % 4)]; // strTem2 = [strTem2 stringByAppendingString: [NSString stringWithFormat: @ "% @", str]; /// else // {// NSString * str = [strTem substringWithRange: NSMakeRange (j * 4, 4)]; // strTem2 = [strTem2 stringByAppendingString: [NSString stringWithFormat: @ "% @", str]; //} NSLog (@ "Received card info. number: % @, expiry: % 02i/% I, cvv: % @. ", info. redactedCardNumber, info. expiryMonth, info. expiryYear, info. cvv); // Use the card info... [scanViewController dismissViewControllerAnimated: YES completion: nil];}