Build on iOS Deprecated

Applies to: Reader SDK - iOSReader SDK - iOS | Mobile Authorization APIMobile Authorization API

Learn how to build a secure in-person payment solution for iOS devices.

Warning

The Square Reader SDK is deprecated and will be retired on December 31, 2025. The SDK is no longer receiving new releases and support for new operating systems isn't guaranteed.

The Mobile Payments SDKMobile Payments SDK launched as the successor of the Reader SDK and is now in General Availability (GA). To ensure continued support and functionality, you should migrate your application from the Reader SDK to the Mobile Payments SDKmigrate your application from the Reader SDK to the Mobile Payments SDK before the retirement date.

Link to section

Requirements and limitations

To complete the following steps, you need:

  • Your application ID - Find your application ID on the Credentials page of your Square application in the Developer Console.
  • Your Reader SDK repository password - Find your Reader SDK repository password on the Reader SDK page of your Square application in the Developer Console.
Link to section

Device compatibility

The Reader SDK isn't compatible to run on custom devices from OEMs that violate Square's security rules or on devices that grant root access to the mobile device operating system code and kernel. As a result, these devices cannot connect to a Contactless and Chip Reader.

The following additional considerations apply when trying to run the SDK on custom devices:

  • The Reader SDK cannot run on custom operating systems.
  • The Reader SDK isn't supported to run on rooted or jailbroken devices.
  • Square prohibits using any software that provides the ability to record or capture screen data or that results in elevated privileges.
  • Verify that your device is supported (see Devices Compatible with the Square Magstripe and Chip Card ReadersDevices Compatible with the Square Magstripe and Chip Card Readers).
  • Supported OS versions should be the latest or as close to the latest as possible.
  • Review Square's support window for the OS version and confirm support for the compilation target version and the runtime version: The compilation target currently supports versions 14 and later.

The following steps are recommended to verify your device:

  1. Test the device with any expected software requirements before committing to using it for the Reader SDK.
  2. Review Square's version support window.
  3. Ensure that you can pair the device with the Reader SDK using Bluetooth.
Link to section

1. Request Reader SDK credentials

  1. Open the Developer ConsoleDeveloper Console. You're prompted to sign in or create an account.

  2. Create a Square application.

  3. Choose the new application to open the Square application settings pages.

  4. Open the Reader SDK page, and then choose Request Credentials to generate your Reader SDK repository password.

    A graphic showing the Reader SDK page in the Developer Console with the generated Reader SDK repository password.

Link to section

2. Install the Reader SDK

Download and configure the latest version of SquareReaderSDK.xcframework in your project root. The framework is installed in the current directory.

Copy
Expand
ruby <(curl https://connect.squareup.com/readersdk-installer) install \ --app-id SQUARE_READER_SDK_APPLICATION_ID \ --repo-password SQUARE_READER_SDK_REPOSITORY_PASSWORD

Optional: If you need to test or revert to a previous version of the SDK, you can also include the desired version number. If unspecified, the most recent version is installed.

Copy
--version 1.6.9
Link to section

3. Configure your iOS project for the Reader SDK

Link to section

Add a Reader SDK build phase

  1. Add the Reader SDK to your project:

    • Open the General tab for your application target in Xcode.
    • Drag the newly downloaded SquareReaderSDK.xcframework into the Embedded Binaries section, and then choose Finish in the dialog box that appears.
  2. Open the Xcode workspace or project for your application.

  3. On the Build Phases tab for your application target, choose the + button (at the top of the pane).

  4. Choose New Run Script Phase.

  5. Paste the following into the editor panel of the new run script:

    Copy
    Expand
    FRAMEWORKS="${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}" "${FRAMEWORKS}/SquareReaderSDK.framework/setup"

    Important

    To avoid "No such file or directory" build errors, make sure that the Reader SDK Run Script phase is the last phase in the list.

Link to section

Disable bitcode

The Reader SDK doesn't currently support bitcode. To disable bitcode:

  1. Open the Build Settings tab for your application target.
  2. In the top right search field, search for "bitcode".
  3. Change the value of Enable Bitcode to NO.
Link to section

Embed Swift libraries

If your application target is pure Objective-C and contains no Swift code, you must include the standard Swift libraries with your application.

  1. Open the Build Settings tab for your application target.
  2. In the top right search field, search for "embed swift".
  3. Change the value of Always Embed Swift Standard Libraries to Yes.
Link to section

Add support for required interface orientations

  1. In Xcode, open the General tab for your application target.

  2. Make sure the Landscape Left and Landscape Right device orientations are supported, as shown:

    An image showing that the Portrait, Landscape Left, and Landscape Right check boxes are selected.

If your application runs on iPhone, it must support portrait and landscape interface orientations so that the Reader SDK can display the signature screen during checkout.

If you want specific screens in your application to only support the portrait orientation, you can override the supportedInterfaceOrientations method in your UIViewController subclasses.

Link to section

Update your Info.plist

Add or update the following key-value pairs on the Info tab for your application target to explain why your application requires these device permissions. Xcode can display human-readable labels (such as Privacy - Microphone Usage Description) rather than the raw keys.

Key Description
NSLocationWhenInUseUsageDescriptionNSLocationWhenInUseUsageDescriptionThis application integrates with Square for card processing. To protect buyers and sellers, Square requires your location to process payments.
NSMicrophoneUsageDescriptionNSMicrophoneUsageDescriptionThis application integrates with Square for card processing. To swipe magnetic cards using the headphone jack, Square requires access to the microphone.
NSBluetoothPeripheralUsageDescriptionNSBluetoothPeripheralUsageDescriptionThis application integrates with Square for card processing. Square uses Bluetooth to connect your device to compatible hardware.
NSCameraUsageDescriptionNSCameraUsageDescriptionThis application integrates with Square for card processing. Upload your account logo, feature photo, and product images with the photos stored on your mobile device.
NSPhotoLibraryUsageDescriptionNSPhotoLibraryUsageDescriptionThis application integrates with Square for card processing. Upload your account logo, feature photo, and product images with the photos stored on your mobile device.
NSBluetoothAlwaysUsageDescriptionNSBluetoothAlwaysUsageDescriptionThis application integrates with Square for card processing. Square uses Bluetooth to connect your device to compatible hardware.

Note

Your application doesn't need to request Bluetooth, Camera, or Photo Library permissions to use the Reader SDK. The usage descriptions are required due to the way the Reader SDK is built.

Link to section

4. Request location permission

Add code to ensure that your application has permission to use location services before starting a checkout flow. The location permission is managed by Apple's CLLocationManagerCLLocationManager class.

Copy
Expand
import CoreLocation class YourViewController: UIViewController { private lazy var locationManager = CLLocationManager() func requestLocationPermission() { switch CLLocationManager.authorizationStatus() { case .notDetermined: locationManager.requestWhenInUseAuthorization() case .restricted, .denied: print("Show UI directing the user to the iOS Settings app") case .authorizedAlways, .authorizedWhenInUse: print("Location services have already been authorized.") } } }
Link to section

5. Request microphone permission

Add code to ensure that your application has permission to access the microphone before starting checkout. The microphone permission is managed by Apple's AVAudioSessionAVAudioSession class. You must have the record permission from AVAudioSession to use Square Magstripe Readers.

Copy
Expand
import AVFoundation extension <#YourViewController#> { func requestMicrophonePermission() { // Note: The microphone permission prompt will not be displayed // when running on the simulator AVAudioSession.sharedInstance().requestRecordPermission { authorized in if !authorized { print("Show UI directing the user to the iOS Settings app") } } } }
Link to section

6. Add code to initialize the Reader SDK

Update the application:didFinishLaunchingWithOptions: method in your application delegate to initialize the Reader SDK.

Copy
Expand
import SquareReaderSDK func application( _: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil ) -> Bool { SQRDReaderSDK.initialize(applicationLaunchOptions: launchOptions) return true }
Link to section

7. Add code to request a mobile authorization code

The Reader SDK requires a mobile authorization code from the Mobile Authorization APIMobile Authorization API. Mobile authorization codes allow custom mobile applications to process payments on Square hardware on behalf of a specific Square account for a given location.

Mobile authorization codes are short lived and should be used immediately to authorize the Reader SDK. Authorization is valid until it's explicitly revoked by calling deauthorize or your application fails to take a payment within 90 days. Mobile authorization codes don't need to be manually refreshed under normal operations.

Did you know?

Production applications should request mobile authorization codes programmatically, but you can generate mobile authorization codes on the Reader SDK page of your application settings or manually with cURLmanually with cURL during development.

Create a function, retrieveAuthorizationCode, to handle the work of calling your authorization service and handling the result.

Copy
Expand
import SquareReaderSDK func retrieveAuthorizationCode() -> String { // TODO: Add code to retrieve a mobile authorization code. return "<Mobile Authorization Code>" }
Link to section

8. Add code to authorize the Reader SDK

Copy
Expand
Link to section

9. Implement CheckoutControllerDelegate methods

Your view controller must conform to the SQRDCheckoutControllerDelegate protocol to handle results and errors from the checkout flow. In most cases, your view controller should implement SQRDCheckoutControllerDelegate. If you choose to implement the delegate as a separate object, make sure it's retained until the checkout flow completes.

Did you know?

This view controller is a good place to add a button that starts the contactless reader connect flow using the Reader SDK settings view controller. A Square contactless reader cannot be connected until the Reader SDK is authorized. Authorization is completed in step 8, which means you can now connect a reader. For information about connecting a reader, see Connect a Contactless ReaderConnect a Contactless Reader.

Copy
Expand
Link to section

10. Add code to start the checkout flow

Create an SQRDCheckoutParameters object. At a minimum, you need to set the amount of money to be charged. You then start the checkout flow by instantiating a Square checkout controller (SQRDCheckoutController) and presenting it.

Copy
Expand
Link to section

11. Add code to handle the checkout result

Implement the success and failure delegate methods. For now, print the checkout result to the Xcode console on success and error information on failure.

The Reader SDK provides error types for all failable operations. For example, errors that occur while presenting the checkout flow are always of the SQRDCheckoutControllerError type. Error objects always contain user displayable details (error codes and descriptions) and debugging information (debug codes and debug messages).

Copy
Expand
Link to section

Test the Reader SDK on iOS

The Reader SDK provides a testing module that contains additional initializers that aren't exposed in the Reader SDK framework. You can use these initializers to construct mock objects in your tests. For example, you might initialize a SQRDCard object in a unit test and use it to verify the behavior of your application.

Copy
Expand
import SquareReaderSDK.Testing // import the Testing module func test_updateWithCard() { let card = SQRDCard(brand: .visa, lastFour: "1111") self.cardView.updateWithCard(card) XCTAssertEqualObjects(self.cardView.lastFourLabel.text, "1111") XCTAssertEqualObjects(self.cardView.brandLabel.text, "Visa") }
Link to section

See also