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

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 4.1.x into Objective-C

  1. Download the kount-ios-sdk from GitHub, and then extract the contents of the SDK.
  2. Add the files from the SDK to the project based on your integration type.
    For Universal Static Library integrations:
    1. Copy libKountDataCollector.a from the Kount SDK and add it in your iOS project. Place the KountDataCollectorUniversalLibrary folder from the Kount SDK inside the folder structure of your iOS project.
    2. Add KountDataCollectorUniversalLibrary to header search paths:
      1. Go to Project Target, Build Settings, and then Header Search Paths.
      2. Add Header search path as ../KountDataCollectorUniversalLibrary.
    For Cocoapods, xcFramework, and other integrations:
    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 then select Add files to “{Project}”.
    3. From the Finder window, select KountDataCollectorUniversalLibrary.
    4. Under KountDataCollectorUniversalLibrary, select folder TouchControls – which contains touch events related files – and then click Add.
  3. 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”
  4. 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");
    }
    }
    }];
  5. 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().
  6. 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.
  7. 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.
  8. 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