If you have not completed the initial integration step, you cannot proceed with this article. Refer to one of the following articles to complete the initial integration steps:
Provide native support for your Kount solution by integrating the Kount iOS SDK (version 4.1.5) into your Swift iOS (version 13.5 and below) application. This allows you to use Kount's service without having to create API calls. Software for this integration can be found in GitHub.
NOTE: This integration document is for iOS versions 13 and above. If your application is using segues, then analytics data only captures for that view controller if modal is presented using UIModalPresentation.fullScreen. For iOS versions below 13, the default presentation style is already full screen, so you do not need to make any changes and analytics data will capture for those screens.
Integrating the Kount iOS SDK into a Swift App
- Copy libKountDataCollector.a from the Kount SDK and add it in iOS project. Place KountDataCollector folder from Kount SDK inside the folder structure of iOS project.
- Add h and KountAnalyticsViewController.h from KountDataCollector inside the iOS project:
- Go to the Project Navigator view.
- Right-click your app’s project name, and then select Add files to “{Project}”.
- From the Finder window, select KountDataCollector.
- Under KountDataCollector, select kDataCollector.h and KountAnalyticsViewController.h, and then click Add.
- Xcode asks to create a bridging header. Click the option to create the header.
- To manually add the bridging header:
- Go to Project Target, Build Settings, and then Header Search Paths.
- Add Header search path as ../KountDataCollector.
- For the Bridging header name, use <Target-name>-Bridging-Header.h.
- Add following import statements in the bridging header file:
#import "KDataCollector.h"
#import "KountAnalyticsViewController.h" - Add the folder for touch event related files (for reference) under Project target.
- Go to the Project Navigator view.
- Right-click your app’s project name, and then select Add files to “{Project}”.
- From the Finder window, select KountDataCollector.
- Under KountDataCollector, select folder TouchControls, which contains touch events related files, and then click Add.
- For iOS 13
Under Scenedelegate.swift, in sceneDidEnterBackground method, add:
KountAnalyticsViewController().registerBackgroundTask()
For versions below iOS 13
Under AppDelegate.swift, in ApplicationDidEnterBackground method, add:
KountAnalyticsViewController().registerBackgroundTask()
- In Appdelegate.swift, write the following code example:
The KountAnalyticsViewController keeps the sessionID in a global variable to be retrieved at any time, named as KountAnalyticsViewController.getAppSessionID.// Global Variable var sessionID : String = "" // In method didFinishLaunchingWithOptions, replace their old Kount configuration related code with following code: KDataCollector.shared().debug = true // Set your Merchant ID KDataCollector.shared().merchantID = 99999 // Insert your valid merchant ID // Set the location collection configuration KDataCollector.shared().locationCollectorConfig = KLocationCollectorConfig.requestPermission // For a released app, you'll want to set this to KEnvironment.Production KDataCollector.shared().environment = KEnvironment.test KountAnalyticsViewController.setEnvironment(KDataCollector.shared().environment) KDataCollector.shared().environment = KEnvironment.test KountAnalyticsViewController().setEnvironmentForAnalytics(KDataCollector.shared().environment) // To collect Analytics Data, set Boolean flag - analyticsData to true. let analyticsData = true KountAnalyticsViewController.collect(sessionID: analyticsSwitch: analyticsData) { (sessionID, success, error) in //Completion block to know whether device data collection is successful/failed with error/failed without error. if (success) { print("Collection Successful") } else { if ((error) != nil) { print("Collection failed with error: ",error!.localizedDescription) } else { print("Collection failed without error") } } }
- In the view controllers where you want to detect events, inherit view controller from KountAnalyticsViewController and remove UITextFieldDelegate (if any).
NOTE: If your view controller does not inherit directly from UIViewController, you must perform this step on the controller that does inherit from UIViewController, and ensure that controller calls super.init(). - In the view controller where you want to capture analytics data, under ViewDidLoad(), add:
<textfield_Name>.delegate = self.
It must be added for all textfields on that page. - In the login view controller, inside the login action method, add:
Inside code for Successful login, add:KountAnalyticsViewController().storeLog(inEvents: true)
Inside code for Unsuccessful login, add:KountAnalyicsViewController().storeLog(inEvents: false)
- If a ViewController in application is overriding the method that we are already using for capturing analytics data, then call super <MethodName> in the ViewController method. This step involves some client-side coding if there are multiple methods, but these will only be one line of code for such methods.
- Almost all Kount API calls require your Kount assigned merchantID and a sessionID (KountAnalyticsViewController.getAppSessionID). You must send the getAppSessionID you created earlier back to your servers. This can be done at any time prior to the Kount API calls being made (from your servers to ours). For example, if you are using Kount Control and plan to evaluate logins, you could include the sessionID along with the users login credentials to your servers. This sessionID is accessible as a global variable. Refer to the Kount Support website for further documentation.
- Build and Run.
Comments
0 comments
Article is closed for comments.