How to Invoke the Device Data Collector from an Objective-C App using the iOS SDK

Provide native support for your Kount solution by integrating the Kount iOS SDK into your Objective-C iOS application. This allows you to use Kount's service without having to create separate API calls. Software for this integration can be found in GitHub.

Invoking the Kount iOS SDK into Objective-C

  1. Add the folder for touch event related files (for reference) under Project target.
    1. Go to the Project Navigator view.
    2. Right-click the app’s project name and select Add files to “{Project}”or move the TouchControls folder to the root of the project in Xcode.
    3. From the Finder window, select KountDataCollectorUniversalLibrary.
    4. Under KountDataCollectorUniversalLibrary, select the TouchControls folder, which contains touch event related files, and then click Add.
    5. Select Copy items if needed​, Create groups​, and then select one or more target destinations for the analytics.
    6. Select Add​.
  2. Add the View Controller to your project.
    For iOS 13 and above:
    Under SceneDelegate.h, add:
        #import “KountAnalyticsViewController.h”
        #import “KDataCollector.h”
    Under SceneDelegate.m, in the sceneDidEnterBackground method, add:
        KountAnalyticsViewController *backgroundTaskObject = [[KountAnalyticsViewController alloc] init];
          [backgroundTaskObject registerBackgroundTask];]
    For iOS 12 and below:
    Under AppDelegate.h, add:
        #import "KountAnalyticsViewController.h"
        #import "KDataCollector.h”
    Under AppDelegate.m, in the ApplicationDidEnterBackground method, add:
        KountAnalyticsViewController *backgroundTaskObject = [[KountAnalyticsViewController alloc] init];
          [backgroundTaskObject registerBackgroundTask];
    Note: For each view in which you want to send Analytics data, in the .h file you must add: #import “KountAnalyticsViewController.h”
  3. In m, write the following code snippet:
    NSString *sessionID = nil;

    [[KDataCollector sharedCollector] setDebug:YES];

    // Set your Merchant ID
    [[KDataCollector sharedCollector] setMerchantID:99999];

    // Set the location collection configuration
    [[KDataCollector sharedCollector] setLocationCollectorConfig:KLocationCollectorConfigRequestPermission];

    // For a released app, you'll want to set this to KEnvironmentProduction

    [[KDataCollector sharedCollector] setEnvironment:KEnvironmentTest];

    [[KountAnalyticsViewController sharedInstance] setEnvironmentForAnalytics: [KDataCollector.sharedCollector environment]];

    //To collect Analytics Data, set Boolean flag - analyticsData to YES.
    BOOL analyticsData = YES;

    [[KountAnalyticsViewController sharedInstance] collect:sessionID analyticsSwitch:analyticsData completion:^(NSString * _Nonnull sessionID, _Bool success, NSError * _Nullable error) {
    //Completion block to know whether device data collection is successful/failed with error/failed without error.

    if (success) {
    NSLog(@"Collection Successful");
    else {
    if(error != nil) {
    NSLog(@"Collection failed with error:%@",error.description);
    else {
    NSLog(@"Collection failed without error");

    If you want to know the status of the DDC, add the following to your code:
        [KountAnalyticsViewController getKDataCollectionStatus]
        [KountAnalyticsViewController getKDataCollectionError]
  4. In the view controller .h file add:
    #import KountAnalyticsViewController.h
    Replace the UIViewController inheritance with KountAnalyticsViewController, and then remove instances of UITextFieldDelegate.
    Note: If your view controller does not inherit directly from UIViewController, perform this step on the controller that does inherit from UIViewController, and make sure the controller calls super.init().
  5. In the view controllers where you want to capture analytics data, under the ViewDidLoad method, add:
    <textfield_Name>.delegate = self
    Note: The code above must be added for all textfields on that page.
    In the login view controller’s .m file, inside the code for Successful login, add:
    [[KountAnalyticsViewController sharedInstance] storeLogInEvents:YES];
    Inside the code for Unsuccessful login add:
    [[KountAnalyticsViewController sharedInstance] storeLogInEvents:NO];
    Note: If a view controller in the application overrides the method that is being used for capturing analytics data, then call [super <MethodName>] in the ViewController method.
  6. Kount API calls require your Kount assigned merchantID and a sessionID (getAppSessionID). Send the KountAnalyticsViewController.getAppSessionID back to your servers before sending the Kount API calls. For example, if you are using Kount Control to evaluate logins, include the KountAnalyticsViewController.getAppSessionID along with the user’s login credentials to your servers.
  7. Build and Run.
    Note: In iOS 13 and above, if your application is using segues and has a modal displayed using UIModalPresentationFullScreen, then analytics data is captured for that view controller. For iOS 12 and below, no changes are required because the default presentation style is full screen.
Was this article helpful?
0 out of 0 found this helpful