Skip to content

Integrate the Tapkey Mobile SDK

Warning

This documentation refers to version 1.15.12.0 and later. This documentation may not be appropriate for older versions. Take a look at the upgrade section for upgrading to the latest version of the Tapkey Mobile SDK.

Sample App

The Tapkey Mobile SDK sample app is available on GitHub, demonstrating how to use the Tapkey Mobile SDK in order to offer the relevant functionality.

Requirements

The Tapkey Mobile SDK is written in Swift and is distributed as a compiled static Swift 5.0 library. Therefore, the target App has to be built at least with Xcode 10.2 and Swift 5.0. Because of missing ABI stability of Swift 4.2 and older, older Xcode versions are not supported.

Add Tapkey Mobile SDK via CocoaPods

The Tapkey Mobile SDK is published as a Pod in an private Podspec repository. To tell CocoaPods where to find the artefacts add the Tapkey Podspec repository, add the official Tapkey Podspec repository as a source to the beginning of the Podfile and add TapkeyMobileLib as a dependency to your target app.

source 'https://github.com/tapkey/TapkeyCocoaPods'
source 'https://github.com/CocoaPods/Specs.git'

target 'App' do
    pod 'TapkeyMobileLib'    
end

Bootstrap the Tapkey Mobile SDK

The Tapkey Mobile SDK expects the AppDelegate of the target application to implement the TapkeyAppDelegate protocol which returns a singleton of TapkeyServiceFactory which has to be created in the willFinishLaunchingWithOptions callback of the target application's AppDelegate.

  1. Import the TapkeyMobileLib module.
  2. Implement the TapkeyAppDelegate protocol.
  3. Use the TapkeyServiceFactoryBuilder to create an instance of the TapkeyServiceFactory in the willFinishLaunchingWithOptions callback.
  4. Implement the missing method getTapkeyServiceFactory() which returns the TapkeyServiceFactory singleton.
import UIKit
import TapkeyMobileLib

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, TapkeyAppDelegate {

    private var tapkeyServiceFactory:TapkeyServiceFactory!;

    func application(_ application: UIApplication,
                     willFinishLaunchingWithOptions launchOptions:
                     [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

        // Build service factory singleton instance
        self.tapkeyServiceFactory = TapkeyServiceFactoryBuilder()            
            .build();
    }

    public func getTapkeyServiceFactory() -> TapkeyServiceFactory {
        return self.tapkeyServiceFactory;
    }
}

Polling Data

To allow unlocking during the device has bad or no network connection, it is essential to frequently fetch and cache data. iOS has a feature that allows to frequently refresh data while the app is in background. To allow Tapkey do cache data, call the Tapkey Mobile SDK during such an event.

  1. Enable background app refresh in your app's entitlements. (Updating your app with background app refresh)
  2. Call PollingManager#poll() in AppDelegate's performFetchWithCompletionHandler callback.
import UIKit
import TapkeyMobileLib

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, TapkeyAppDelegate {

    func application(_ application: UIApplication,
        performFetchWithCompletionHandler completionHandler:
            @escaping (UIBackgroundFetchResult) -> Void) {

        // Run using runAsyncInBackground to prevent freezing while data is polled
        runAsyncInBackground(application, promise: self.tapkeyServiceFactory.getPollingManager()
            .poll(with:JavaUtilHashSet())
            .finallyOnUi {
                completionHandler(UIBackgroundFetchResult.newData);
            }
        );
     }
}

When and how often the performFetchWithCompletionHandler callback will be called is decided by iOS and depends from different device metrics (e.g. battery level, network level, etc.). There is no way to enforce background fetch after an exact timespan.