Getting started with the iOS SDK
Getting started with the iOS SDK requires five steps:
- Install the SDK in your app
- Configure your app
- Set up the connection token endpoint in your app and backend
- Initialize the SDK in your app
- Connect your app to the simulated reader
Just getting started with Terminal? Check out our example applications to get your own integration set up quickly.
Install the SDKClient-side
The Stripe Terminal iOS SDK is compatible with apps supporting iOS 9 and above, and can be installed with CocoaPods or by manually integrating the framework.
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository or subscribe to the Github Releases RSS feed.
For information on migrating from beta versions of the iOS SDK, see the Stripe Terminal Beta Migration Guide.
Configure your appClient-side
To prepare your app to work with the Stripe Terminal SDK, make a few changes to your Info.plist file in Xcode.
Enable location services with the following key-value pair.
Privacy – Location When In Use Usage Description Key NSLocationWhenInUseUsageDescription Value Location access is required in order to accept payments. To reduce fraud risks associated with payments, and to minimize disputes, Stripe needs to know where payments occur. If the SDK can’t determine the location of the iOS device, payments are disabled until location access is restored.
Ensure that your app runs in the background and remains connected to the reader.
Required background modes Key UIBackgroundModes Value bluetooth-central (Uses Bluetooth LE accessories) Setting the bluetooth-central background mode lets the reader remain in standby mode when your app is backgrounded, or when the iOS device is locked. Without this value, standby fails. When your app is running in the background, the reader can turn off automatically to conserve power.
Pass app validation checks when submitting to the App Store.
Privacy – Bluetooth Peripheral Usage Description Key NSBluetoothPeripheralUsageDescription Value Bluetooth access is required in order to connect to supported card readers. This is an example—you can rephrase the prompt for user permission in your app.
iOS 13 SDK and later: Allow your app to display a Bluetooth permission dialog.
Privacy - Bluetooth Always Usage Description Key NSBluetoothAlwaysUsageDescription Value This app uses Bluetooth to connect to supported card readers. iOS 13 introduces new, more granular permissions surrounding an app’s use of Bluetooth peripherals. Any apps that use the device’s Bluetooth APIs must include this key in their Info.plist file, or else they will crash on first launch.
Save your app’s Info.plist. Now it’s configured correctly and ready for use with the Stripe Terminal SDK.
Set up the ConnectionToken endpointServer-sideClient-side
Server-side
To connect to a reader, your backend needs to give the SDK permission to use the reader with your Stripe account, by providing it with the secret from a ConnectionToken. Your backend should only create connection tokens for clients that it trusts.
Obtain the secret from the ConnectionToken on your server and pass it to the client side.
The ConnectionToken’s secret lets you connect to any Stripe Terminal reader and take payments with your Stripe account. Be sure to authenticate the endpoint for creating connection tokens.
Client-side
To give the SDK access to this endpoint, implement the ConnectionTokenProvider protocol in your app, which defines a single function that requests a ConnectionToken from your backend.
This function is called whenever the SDK needs to authenticate with Stripe or the Reader. It’s also called when a new connection token is needed to connect to a reader (for example, when your app disconnects from a reader). If the SDK is unable to retrieve a new connection token from your backend, connecting to a reader fails with the error from your server.
Do not cache or hardcode the connection token. The SDK manages the connection token’s lifecycle.
Initialize the SDKClient-side
The Terminal
class made available by the Stripe Terminal SDK exposes a generic interface for discovering readers, connecting to a reader, creating payments, and updating reader software.
To get started, provide your ConnectionTokenProvider
implemented in Step 3. You can only call setTokenProvider
once in your app, and must call it before accessing Terminal.shared
. We recommend calling setTokenProvider
in your AppDelegate’s application:didFinishLaunchingWithOptions
method. Alternatively, you can use dispatch_once
in Objective-C, or a static
constructor in Swift.
Connect to the simulated readerClient-side
The Stripe Terminal SDK comes with a built-in simulated card reader, so you can develop and test your app without connecting to physical hardware. Whether your integration is complete or you’re just starting out, use the simulated reader to emulate all the Terminal flows in your app: connecting to a reader, updating reader software, and collecting payments.
Note that the simulated reader does not provide a UI. After connecting to it in your app, you can see it working when calls to the Stripe SDK succeed.
To use the simulated reader, call discoverReaders to search for readers, with the simulated
option set to true
. When discoverReaders
returns a result, call connectReader to connect to the simulated reader.
SDK updates
Stripe periodically releases updates to the Stripe Terminal JavaScript SDK, the Stripe Terminal iOS SDK, and the Stripe Terminal Android SDK, which can include new functionality, bug fixes, and security updates. Update your integrated version of the Stripe Terminal JavaScript, iOS, or Android SDK as soon as a new version is available.