SDK overviewAndroidiOSDemoChangelog

SDK Configuration

The SDK can be configured when the application starts (in AppDelegate’s application: didFinishLaunchingWithOptions method for UIKit framework or in @main App’s init method for SwiftUI framework).

DateioSdkApp is a singleton object. Configure method should be called only once in the application.

Api configuration example

Basic API parameters can be changed using the DateioSdkApiConfiguration protocol. You can change API server URL host or request headers (add custom Authorization header etc.).

import Foundation
import DateioSDKiOS

final class DateioSdkApiConfigurationImpl: DateioSdkApiConfiguration {
    var urlHost: String? = "https://your_bank_BE/dateio"
    var httpRequestHeaders: [String : String]?
    
    var deviceHttpRequestHeaders: [String] = [
        "mobile ios",
        "BANK_NAME_APP [version X.Y.Z]"
    ]

    var sslPins: [String : [String]]?

    func getRequestHeaders(completion: @escaping ([String : String]) -> Void) {
        TokenProvider().getToken { token in
            completion(
                [
                    "Accept-Language": languageIdentifier,
                    "BANK_TOKEN_KEY": token
                ]
            )
        }
    }
}

Make sure that you set deviceHttpRequestHeaders parameters correctly, as this will help us solve potential issues and identify requests by platform. mobile ios is a static value and should not be changed. BANK_NAME_APP [version X.Y.Z] should contain your application or bank name and app version. The exact format is not required and depends on your preferences. Setting user device information is also helpful.

Configure SDK in AppDelegate:

import UIKit
import DateioSDKiOS

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Configure SDK
        DateioSdkApp.shared.configure(
            with: nil,
            apiConfiguration: DateioSdkApiConfigurationImpl(),
            localizationConfiguration: nil
        )

        return true
    }
}

Configure SDK in SwiftUI App

import SwiftUI
import DateioSDKiOS

@main
struct Demo: App {

    // MARK: - Init

    init() {
        DateioSdkApp.shared.configure(
            with: nil,
            apiConfiguration: DateioSdkApiConfigurationImpl(),
            localizationConfiguration: DateioSdkLocalizationConfigurationImpl()
        )
    }

    // MARK: - Body

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Working with user token

There are two ways to pass an access token in the request header.

The first one is more suitable for testing purposes or if the token has a long-term validity. Just pass the token within the DateioSdkApiConfiguration protocol in the httpRequestHeaders variable.

import Foundation
import DateioSDKiOS

final class DateioSdkApiConfigurationImpl: DateioSdkApiConfiguration {
    var httpRequestHeaders: [String : String] = [
        "BANK_TOKEN_KEY": token
    ]
}

The second, dynamic approach uses the getRequestHeaders function of the DateioSdkApiConfiguration protocol.

This method is called before each request and waits for the request headers to be passed in, which are then passed in the request. Within this method, other services can be called asynchronously to receive the token. It is good practice to cache the data (if the token expiration is known) and not call the services every time.

import Foundation
import DateioSDKiOS

final class DateioSdkApiConfigurationImpl: DateioSdkApiConfiguration {
    func getRequestHeaders(completion: @escaping ([String : String]) -> Void) {
        SomeTokenProvider().getToken { token in
            completion(
                [
                    "Accept-Language": languageIdentifier,
                    "BANK_TOKEN_KEY": token
                ]
            )
        }
    }
}

You can also use func getRequestHeaders(requestInfo: [String: String?], completion: @escaping ([String : String]) -> Void) when you need requests info that SDK generate. Eg. for PowerAuth.

Other SDK methods

This section describes other SDK functions and settings.

ConfigurationOnApiErrorCallback protocol

You can set a callback in case an API error occurs. This callback has two methods, one specifically for 401 authentication error and the other one for all the other types of errors. Use it in DateioSDKApp.shared.configure(apiErrorCallbackConfiguration:) call.

final class ApiErrorCallbackConfiguration: ConfigurationOnApiErrorCallback {
    func onAuthErrorCallback() {
        // Do something here, when 401 error occurred during an API call
    }

    func onGeneralApiError(errorCode: Int32) {
        // Do something here in case other generic error occurred
    }
}

async DateioSdkApp.shared.registerUserOnApiWith()

Will register user on Dateio BE. This call is intended to be used once the user give all consents with program usage. Return true / false based on result. For details see user consents section.

async DateioSdkApp.shared.deleteUserOnApiWith()

Will delete user on Dateio BE. Return true / false based on result. For details see user consents section.

async DateioSdkApp.shared.logoutUserOnApiWith()

Will logout user on Dateio BE. Return true / false based on result.

async DateioSdkApp.shared.loadCashbackHistoryTotals()

To load cashback history totals outside of SDK screens, use this method. This method returns a CashbackHistoryTotals object with the following parameters:

toPayTotal: Double
toPayTotalCurrency: String
paidTotal: Double
paidTotalCurrency: String

When you use this function you must authenticate user before navigating within the SDK.This function should only be used for registered users.

Example how to use this function:

import UIKit
import DateioSDKiOS

final class CashbackHistoryTotalsCell: UITableViewCell, UITextFieldDelegate {
    @IBOutlet weak var title: UILabel!
    @IBOutlet weak var amountTitle: UILabel!
    @IBOutlet weak var amount: UILabel!
    @IBOutlet weak var bgView: UIView!

    // MARK: - Init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        loadData()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        loadData()
    }

    // MARK: - Load data
    private func loadData() {
        Task {
            let data = await DateioSdkApp.shared.loadCashbackHistoryTotals()
            amount.text = "(data?.toPayTotal ?? 0) (data?.toPayTotalCurrency ?? "")"
        }
    }

    // MARK: - Setup
    func setup() {
        setupBgView()
        title.text = "Cashback"
        amountTitle.text = "Saved this month"
    }

    private func setupBgView() {
        backgroundColor = .clear
        contentView.backgroundColor = .clear

        bgView.backgroundColor = .white
        bgView.layer.cornerRadius = 12
        bgView.layer.masksToBounds = true

        bgView.layer.shadowColor = UIColor.black.cgColor
        bgView.layer.shadowOpacity = 0.1
        bgView.layer.shadowOffset = CGSize(width: 0, height: 2)
        bgView.layer.shadowRadius = 4
        bgView.layer.masksToBounds = false
    }
}

DateioSdkApp.shared.destroy()

Will free up all resources in configuration object. Call this function when user logs out from bank application. This will clear the SDK configuration and all its information. When this function is called, you will have to configure the SDK again in further usage.

async DateioSdkApp.shared.loadNewOffersCount()

Will return number of new offers for user. This is intended for “red dot” use case.

DateioSdkApiConfiguration.sslPins = ["domain" : ["hash"]]

Will use this SSL hashes for given domains. SDK will not trust to other certificates. Use it in DateioSDKApp.shared.configure(apiConfiguration:) call.

mainScene?.processNotification

You can pass data from push notifications via this method to SDK. SDK will perform given action e.g. redirect to detail and delete passed data. notification is DateioSDKShared.Notification object with two parameters. Notification type enum NotificationType and objectId (In some cases you need to pass objectId so SDK knows which offer or category should be redirected.). Function return Bool value which correspond to process success.

For example:

private func processOpenOfferDetail() {
    Task {
        await mainScene?.processNotification(
            notification: DateioSDKShared.Notification(notificationType: .openOfferDetail, objectId: 15746642515)
        )
    }
}

Notifications can trigger the following types of actions:

  1. openOffersList - will open SDK on offer list. Same if you navigate to SDK without processNotification.
  2. openOfferDetail - will open offer detail. Need pass objectId as offer id.
  3. openOfferHistory - will open user history with transactions.
  4. openOfferCategory - will open offers list in given category. Need pass objectId as category id.
  5. openOfferMap - will open a map with offers on it.
  6. activateOffer - use this type when you want directly activate offer without navigating to SDK. Need pass objectId as offer id. Note that you will still need to authenticate the user as usual.

This method is intended mainly for push notifications but might be used as well for in-app banners and others.

Configuration.BankLoggerConfiguration

Configuration.BankLoggerConfiguration file is Protocol ConfigurationBankLoggerCallback implementation. It allows set custom logging for actions which happen inside the SDK. In the protocol, it is necessary to implement function func logAction(AnalyticsAction: String, AnalyticsOrigin: String?, id: String?, info: String?)which is called on user activity.

Inside the SDK, the logging function is called like asynchronous Task without a try block, as its behavior needs to be implementation-specific.

Task {
    Configuration.shared.getBankLoggerCallback?.logAction(action: action, origin: AnalyticsOrigin.gallery, id: nil, info: nil)
 }

You also need to handle error states appropriately in this function.

AnalyticsAction.PAGE_ENTER and AnalyticsAction.PAGE_LEAVE actions are called when .onAppear or .onDisappear event starts on a page view.

DateioSdkApiConfiguration.allowedOfferTypes = [OfferType]

Will enable only some offer types - you might use values defined in DateioSDKShared.OfferType. Use it in DateioSDKApp.shared.configure(apiConfiguration:) call.

This method should be used only after consultation with Dateio as this will reduce number of available offers.

DateioSdkApiConfiguration.apiVersion = Int32

You can change SDK API version. In case you change the API version, warning will be logged, since this should be used only in edge cases. Use it in DateioSDKApp.shared.configure(apiConfiguration:) call.

This parameter should be used only after consulting with Dateio in advance, since it might cause errors when set incorrectly.

Map applications chooser

The SDK supports system applications chooser when user clicks on store in offer detail. If the user has installed any of these applications:

  • Google maps
  • Waze
  • Citymapper

Chooser will be shown with available options. To use this feature, you need to add the following code to Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
    <string>waze</string>
    <string>citymapper</string>
</array>

Where to head next

By this point you are able to load offers and other data for given user. Now, you can continue to last step - SDK customization to get same look and feel as your app.