Skip to main content

Initialize the iOS SDK

Once the SDK has been added to your project, you will need to initialize it. The initialization process will run on a background thread. This will prepare the SDK for interactions with the user, and your application.

SDK initialization requires a Configuration ID which is generated in Console. To learn more, see ATS Mobile SDK.

How to Initialize the iOS SDK

  1. Import the SDK module to where you want to use it.

    Swift

    import LRAtsSDK

    Objective-C

    #import <LRAtsSDK/LRAtsSDK-Swift.h>
  2. (Optional, but recommended) Implement the SDK delegate methods. This will allow the host application to track the SDK initialization status.

    Swift

    LRAts.shared.delegate = self

    Objective-C

    [[LRAts shared] delegate] = self;
  3. Create configuration object by providing your Config ID (appID).

    Swift

    let lrAtsConfiguration = LRAtsConfiguration(appId: <#String#>)

    Objective-C

    LRAtsConfiguration *lrAtsConfiguration = [[LRAtsConfiguration alloc] initWithAppId:<#(NSString * _Nonnull)#>];
  4. Initialize SDK with LRAtsConfiguration object. The initialization runs on a background thread to avoid blocking your UI.

    Note

    Your application must check for ATT consent before initializing our SDK.

    Swift

    LRAts.shared.initialize(with: lrAtsConfiguration) { success, error in
        if success {
            print("SDK is Ready")
        } else {
            print("SDK init error: \(String(describing: error))")
        }
    }

    Objective-C

    [[LRAts shared] initializeWith:lrAtsConfiguration completion:^(BOOL success, NSError * _Nullable error) {
        if (success) {
            NSLog(@"init successful");
        } else {
            NSLog(@"init failure");
        }
    }]

Caution

After the initialization process is complete, if the ATS placement tied to the Config ID is still not yet approved, the SDK will return fake data which should only be used for testing. Information regarding the placement status can be found in the log output of the SDK.