iOS Integration
SDK integration:
mobileToken
required!This page provides detailed steps on how to add the iOS SDK to your project. Please ensure you have reviewed the general Mobile SDK overview before continuing. To start using the iOS SDK, make sure your backend can generate a
mobileToken
via the init endpoint. With this token, your iOS app can initialize and launch transactions.
Integration
For iOS, you can add the SDK to your project by adding a new Swift package dependency in Xcode and pointing to the github repository github.com/datatrans/ios-sdk
. By default, enable all packages presented in the package selection. If you are building an App Clip project, you may select only your required packages, which will depend on your payment methods and flows. Please contact our support if you are unsure about what packages you require. Besides adding the packages via a Swift package dependency, you can also add the SDK via Cocoapods with pod 'Datatrans'
.
Call the library with your mobile token to start a transaction. You can optionally specify further options and pass tokens for fast checkouts with our provided classes. Below is an example of the suggested minimum options to start a transaction with iOS (Swift, Objective-C). Please read our detailed class description for iOS to discover more initialization options.
let transaction = Transaction(mobileToken: String)
transaction.delegate = self // you must implement your TransactionDelegate here
transaction.options.testing = true
transaction.options.useCertificatePinning = true
transaction.start(presentingController: navigationController)
DTTransaction* transaction = [[DTTransaction alloc] initWithMobileToken:mobileToken ];
transaction.delegate = self; // you must implement your TransactionDelegate here
transaction.options.testing = YES;
transaction.options.useCertificatePinning = YES;
[transaction startWithPresentingController:self.navigationController];
Info.plist file
To integrate a card scanner into your iOS app, you must include a camera usage description in your Info.plist file. This explains to users why your app requires camera permissions. If you omit this description, your app might crash when using the card scanner feature.
Additionally, if you want to integrate alternative payment methods like Klarna, PostFinance, Swish, Twint, or Vipps, you'll need to configure your app to switch between your app and the respective payment app smoothly. For iOS, this involves adding the LSApplicationQueriesSchemes
array to your Info.plist and listing the necessary payment app schemes (see example below).
#CameraUsage
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) requires camera access to scan cards.
#Klarna
Key : LSApplicationQueriesSchemes
Value : [ "klarna", "klarnaconsent" ]
#PostFinance
Key : LSApplicationQueriesSchemes
Value : [ "postfinance-epayment" ]
#Swish
Key : LSApplicationQueriesSchemes
Value : [ "swish" ]
#Twint
Key : LSApplicationQueriesSchemes
Value : [ "twint-extended", "twint-issuer1", ... , "twint-issuer39" ]
#Vipps
Key : LSApplicationQueriesSchemes
Value : [ "vipps", "vippsMT" ]
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) requires camera access to scan cards.</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>klarna</string>
<string>klarnaconsent</string>
<string>postfinance-epayment</string>
<string>swish</string>
<string>vipps</string>
<string>vippsMT</string>
<string>twint-extended</string>
<string>twint-issuer1</string>
<string>twint-issuer2</string>
<string>twint-issuer3</string>
<string>twint-issuer4</string>
<string>twint-issuer5</string>
<string>twint-issuer6</string>
<string>twint-issuer7</string>
<string>twint-issuer8</string>
<string>twint-issuer9</string>
<string>twint-issuer10</string>
<string>twint-issuer11</string>
<string>twint-issuer12</string>
<string>twint-issuer13</string>
<string>twint-issuer14</string>
<string>twint-issuer15</string>
<string>twint-issuer16</string>
<string>twint-issuer17</string>
<string>twint-issuer18</string>
<string>twint-issuer19</string>
<string>twint-issuer20</string>
<string>twint-issuer21</string>
<string>twint-issuer22</string>
<string>twint-issuer23</string>
<string>twint-issuer24</string>
<string>twint-issuer25</string>
<string>twint-issuer26</string>
<string>twint-issuer27</string>
<string>twint-issuer28</string>
<string>twint-issuer29</string>
<string>twint-issuer30</string>
<string>twint-issuer31</string>
<string>twint-issuer32</string>
<string>twint-issuer33</string>
<string>twint-issuer34</string>
<string>twint-issuer35</string>
<string>twint-issuer36</string>
<string>twint-issuer37</string>
<string>twint-issuer38</string>
<string>twint-issuer39</string>
</array>
Twint requires you to define 40 schemes to support app switches to their many apps. If you have limited space due to other integrations (iOS has a limit of 50 schemes), use the SDK option twintMaxIssuerNumber
. Set this value to match your highest twint-issuerXY
scheme. For example, if Info.plist contains up to twint-issuer35
, set the SDK option twintMaxIssuerNumber
to 35
. Make sure the twint-extended
scheme is always included in your Info.plist file.
If possible, always make room for 40 Twint schemes!
Whenever possible, allocate the full 40 Twint schemes within
LSApplicationQueriesSchemes
. This ensures the best possible user experience, allowing for seamless app switching during payments.While the
twintMaxIssuerNumber
option can be used as a workaround if you face scheme limitations, it negatively impacts the user experience. Using this option prevents smooth automatic app switching during the Twint payment process.
Additional requirements for iOS
To enable Apple Pay in your iOS projects, you must create an Apple merchant identifier, upload a certificate to your Datatrans merchant settings and activate the Apple Pay capability in XCode. Please refer to the section Apple Pay via Mobile SDK to correctly enable Apple Pay for your XCode project.
To correctly process PayPal transactions in your iOS projects, you will need to include an additional component from PayPal called PPRiskMagnes
. To correctly process Klarna transactions, you will need to include the additional component from Klarna called KlarnaMobileSDK
. These are optional libraries if you link our SDK via Swift Package Manager. If you linked the SDK via CocoaPods, the component will automatically be added to your project.
If you are processing Twint, PostFinance Card, or PayPal please make sure to define your app callback scheme in the transaction options, as this is required to properly redirect users back to your app.
transaction.options.appCallbackScheme = "your_scheme"
transaction.options.appCallbackScheme = @"your_scheme";
After the transaction
After the transaction has been completed, you can refer to the class TransactionSuccess
that will return the details of the transaction, including the payment method, the transaction unique identifier, and the token if one was created. If the transaction failed, you will have to refer to the class TransactionError
for further details instead. You may also implement TransactionDelegate
to be notified when a transaction is successfully finalized, encounters an error, or is canceled by the user. We will also return the transaction information to your defined webhook, as defined here.
Styling the theme
You can style various colors in our iOS SDK to match your corporate identity. Check the graphic below to see what color properties can be defined. On iOS, you can define your preferred colors within the class ThemeConfiguration
.

Property | Description | Property |
---|---|---|
Background Colorยน | Background color of the navigation bars. If this is not specified, the navigation bars will be transparent. | barBackgroundColor |
Bar Link Colorยฒ | Color of the buttons in the navigation bars. If this is not specified, the color will be the color set in Link Color. | barLinkColor |
Bar Title Colorยณ | Color of the title within the navigation bars. If this is not specified, the color will be the text color. The text color is either white or black and cannot be customized. | barTitleColor |
Button Colorโด | Background color of large buttons, such as the Pay button. If this is not specified, the color will be the color set in Link Color. | buttonColor |
Button Text Colorโต | Text color of large buttons, such as the Pay button. If this is not specified, the color will be set to white. | buttonTextColor |
Link Colorโถ | Color of text-only buttons or links and the text cursor. If this is not specified, the link color will be in a blue tone. | linkColor |
Updated 3 days ago