Menu

General iOS Integration Guide


The easiest way to integrate DyScan is by using CocoaPods, which is covered in this guide. However, if you would rather include DyScan as a dynamic framework, click here. If you would rather include DyScan as a static framework, click here.

Once we add your GitHub username to our organization, copy this podspec to your local machine.

Then, add the following line to your project Podfile, replacing X.X with the Swift version you are using (currently 4.2 and 5.0 are supported):

pod 'DyScan/X.X', :podspec => '/path/to/file/DyScan.podspec'


Include the use_frameworks! line in your Podfile if you have not done so already (see here for a sample Podfile). Then in a terminal in the directory of your iOS project, run

$ pod install


If your app does not already ask for camera permissions, add the key “NSCameraUsageDescription” (Privacy - Camera Usage Description) to your app's Info.plist file. You should set the value to be the string a user sees when they are prompted for the camera permission (e.g. To scan credit cards).

Next Steps

If your app already has card.io, see the migrating from card.io guide.

You can use DyScan in two ways:

  • As a view controller: Quick and easy. Create a view controller that is presented modally. The DyScan view controller handles all aspects of the UX.
  • As a view: More flexible. Create a DyScanView to do card scanning only and manage everything else yourself. This enables a broader range of presentations, such as in-place transitions, but requires that you handle the rest of the UI yourself.

  • Integrating as a View Controller

    First, import Dyscan in the file that contains the view controller that will instantiate DyScan.

    In your app, create an extension for your view controller that conforms to DyScanViewControllerDelegate. This will require you to implement two functions, userDidCancel, and userDidProvide. userDidCancel is called whenever a scan event is unsuccessful (even if that means the user didn't explicitly cancel).

    
    extension ExampleViewController: DyScanViewControllerDelegate{
        func userDidCancel(_ paymentViewController: DyScanViewController!) {
            paymentViewController.dismiss(animated: true, completion: nil)
            
            // Implement functionality after user cancels
        }
        
        func userDidProvide(_ cardInfo: DyScanCreditCardInfo!, in paymentViewController: DyScanViewController!) {
            paymentViewController.dismiss(animated: true, completion: nil)
            
            // Implement functionality after card is read (information is stored in cardInfo)
        }
    }

    If you are using Stripe, see this guide for what functions to implement here. The cardInfo object holds the following fields:
     
    cardNumber:String
    expiryMonth:UInt
    expiryYear:UInt
    isFraud:Bool
            

    Which can be passed to other parts of your app. Note that isFraud is currently always false.
    To instantiate DyScan, create an instance of DyScanViewController, and set the paymentDelegate attribute of it to your view controller (using self). Then, present the view controller to get your users scanning.

    let viewController = DyScanViewController()
    viewController.paymentDelegate = self
    viewController.apiKey =  "{YOUR API KEY}" 
    let navigationController = UINavigationController(rootViewController: viewController)
    present(navigationController, animated: true, completion: nil)

    If you would like to customize the appearance of the view controller, see the documentation here.


    Integrating as a view

    First, import Dyscan in the file that contains the view controller that will instantiate DyScan.

    In your app, create an extension for your view that conforms to DyScanViewDelegate. This will require you to implement two functions, noCameraPermission, and dyScanView.

    
    extension ExampleViewController: DyScanViewDelegate{
        func noCameraPermission(_ dyScanView: DyScanView!) {
    
            //Implement functionality when camera permissions are not given
        }
        
        func dyScanView(_ dyScanView: DyScanView!, didScanCard cardInfo: DyScanCreditCardInfo?) {
            
            //Implement functionality when scanning completes (information is stored in cardInfo, will be nil if scan failed)
            
        }
    

    The cardInfo object holds the following fields:
     
    cardNumber:String
    expiryMonth:UInt
    expiryYear:UInt
    isFraud:Bool
    
            

    Which can be passed to other parts of your app. Note that isFraud is currently always false.
    To instantiate DyScan, create an instance of DyScanView, and set the delegate attribute of it to your view controller (using self). You will need to call the prepare() function to fully initialize the view before adding it as a subview. For example, DyScanView could be added like this:

     dyScanView = DyScanView(frame: CGRect(x: 0, y: 100, width: self.view.frame.width
                , height: self.view.frame.width))
            dyScanView?.apiKey = "{YOUR API KEY}"
            dyScanView?.delegate = self
            dyScanView?.prepare()
            self.view.addSubview(dyScanView!)

    If you would like to allow for the user to switch to a vertical card scanning experience, use the DyScanView.rotate function

    If you would like to customize the appearance of the view controller, see the documentation here.


    Customizing the Appearance

    The DyScan UI is customizable through the following options
    showNumberOverlay:Bool Whether to show the number overlay. Defaults to true. The next three options have no effect if showNumberOverlay is false.
    numberOverlayOpacity:CGFloat The opacity of the number overlay text. Defaults to 0.3.
    defaultCardNumberText:String The card number shown in the number overlay text. Defaults to "4242 4242 4242 4242".
    defaultExpirationDate:String The expiration shown in the number overlay text. Defaults to "11/11".

    showCorners = true Whether to show the corners found by the scanner or not. Defaults to true. The next four options have no effect if showCorners is false
    cornerThickness:int The thickness of lines that show the corners. Defaults to 5.
    cornerInactiveColor:UIColor The color of the corner in its normal, no corner found state. Defaults to UIColor.gray.
    cornerActiveColor:UIColor The color of the corner when it has found a corner. Defaults to UIColor.cyan.
    cornerCompletedColor:UIColor The color of the corner when scanning is completed. Defaults to UIColor.green.

    bgColor:CGColor The color of the background. Defaults to UIColor.gray.cgColor.
    bgOpacity:Float The opacity of the background. Defaults to 0.45.

    lightTorchWhenDark:Bool Whether to use the torch automatically in dark environments. Defaults to true
    vibrateOnCompletion:Bool Whether to cause the phone to vibrate on a successful scan. Defaults to true

    The following fields can only be used in the view controller:
    showHelperText:Bool Whether to show the helper text. Defaults to true. The next four options have no effect if showHelperText is false.
    language:String The language to display. Defaults to NSLocale.current.languageCode. Note that if you set helperTextString it overrides this.
    helperTextString:String The text displayed in helper text. Defaults to nil.
    helperTextColor:UIColor The color of the helper text. Defaults to UIColor.white.
    helperTextVerticalOffset:Float As a fraction of the height of the screen, how far down the helper text should be. Defaults to 0.55.

    showRotateButton:Bool Whether to show the button to support vertical cards better. Defaults to false.
    scanRegionVerticalOffset:Float As a fraction of the height of the screen, how far down the scanning region should be. Defaults to 0.15.

    Get Started