Skip to main content

Code Examples for iOS ATS Mobile SDK

Check out some useful snippets and code examples for initialization below.

Swift
import UIKit
import LRAtsSDK

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // set fake consent (for testing purposes only!), this should be handled by CMP SDK
        UserDefaults.standard.set("1111111111",
                                  forKey: "IABTCF_PurposeConsents"
        )
        UserDefaults.standard.set("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
                                  forKey: "IABTCF_VendorConsents"
        )    
        LRAts.shared.initialize(with: LRAtsConfiguration(appId: "40b867f9-93cc-4687-a2c7-d02bed91aaee")) { success, error in
            if success {
                LRAts.shared.getEnvelope(LREmailIdentifier("test@mail.com")) { lrEnvelope, error  in
                    if let envelope = lrEnvelope?.envelope {
                        // use envelope here
                    }
                }
            }
        }
    }
}
Objective-C
#import "ViewController.h"
#import <LRAtsSDK/LRAtsSDK-Swift.h>

@interface ViewController ()

@end


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // set fake consent (for testing purposes only!), this should be handled by CMP SDK
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@"1111111111" forKey:@"IABTCF_PurposeConsents"];
    [defaults setObject:@"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" forKey:@"IABTCF_VendorConsents"];

    [[LRAts shared] initializeWith:[[LRAtsConfiguration alloc] initWithAppId:@"40b867f9-93cc-4687-a2c7-d02bed91aaee" isTestMode:NO logToFileEnabled:NO] completion:^(BOOL success, NSError * _Nullable error) {
        if (success) {
            [[LRAts shared] getEnvelope:[[LREmailIdentifier alloc] init:@"test@mail.com"] completion:^(LREnvelope *lrEnvelope, NSError *error) {
                if (lrEnvelope.envelope != nil) {
                    // use envelope here
                }
            }];
        }
    }];
}

@end