Skip to main content

Call the APIs

This section guides you through the Mobile SDK APIs you can use to help you retrieve envelopes more efficiently.

Each method with a callback below has an async/await counterpart which is available for iOS 15 and above.

initialize

To use the ATS SDK, the initialization method needs to be called to start the initialization process. For more information, see Initialize the iOS SDK.

Name

Type

Description

configuration

LRAtsConfiguration

The object that contains a Config ID.

completion

LRInitializeCompletion

(success: Bool, error: Error?)

Completion handler to call when the initialization process is finished.

getEnvelope

This method returns envelope for the specified identifier. Phone numbers as identifiers are only supported in the U.S..

To retrieve a valid envelope, your ATS placement must be in an approved state. If the placement is unapproved, 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.

Caution

To retrieve envelopes, the bundle ID of your application must first be approved by a LiveRamp representative.

Name

Type

Description

lrIdentifierData

Choose one of the following (do not use LRIdentifierData directly):

Non-hashed or hashed identifier for which the envelope is requested.

completion

LRGetEnvelopeCompletion

(envelope: LREnvelope?, error: LRError?)

Completion handler to call when the envelope has been retrieved.

Returns: No return parameter.

Example using completion handler:

let lrEmailIdentifier = LREmailIdentifier("test@email.com")
LRAts.shared.getEnvelope(lrEmailIdentifier) { result, error in
    guard let envelope = result?.envelope else {
        print("Couldn't retrieve envelope. Error: \(error)")
        return
    }
    print("Received envelope: \(envelope)")
}

Example using async/await

do {
    let lrEmailIdentifier = LREmailIdentifier("test@email.com")
    let envelope = try await LRAts.shared.getEnvelope(lrEmailIdentifier)
    print("Received envelope: \(envelope)")
} catch {
    print("Couldn't retrieve envelope. Error: \(error)")
}

Note

You can verify if an envelope has been successfully fetched by using a network HTTP proxy tool (such as Charles), and filter for the api.rlcdn call.

resetSDK

Calling this method will remove all data related to LRAtsSDK. To use the SDK after calling this method, you have to go through the initialization process again.

Parameters: No parameters.

Returns: No return parameters.

sdkVersion

LRAts.sdkVersion is a property used for checking which version of the SDK you are currently running.

shared

LRAtsSDK.shared is a singleton instance that contains references to the public API.

Example: LRAts.shared.resetSDK()

delegate

This property is used to subscribe/unsubscribe to LREvent and for dispatching events and errors.

hasConsentForNoLegislation

This property will be used for countries that are outside of the geo-targeting legislation configured in Console. If set to true, SDK will proceed even if there is no legislation.

The default value for this property is false.

isDisabled

This property is used to control the status of the SDK. When set to true, the SDK becomes disabled. As a result, the APIs will not function and API calls will not be possible. Setting the property to false changes the SDK status to notInitialized and re-initialization is required before API calls can be made again.

The default value of this parameter is false.

status

This property provides information about the SDK status which value is a type of LRStatus.

The default value of this property is notInitialized.

LREmailIdentifier

LREmailIdentifier class implements the LRIdentifierData protocol. As an object, LREmailIdentifier is used to obtain envelopes as one of the possible parameters of the getEnvelope method.

The LREmailIdentifier object can be instantiated using one of the following constructors:

  • With a constructor that accepts mail as a string (Swift).

    LREmailIdentifier("test@mail.com")
  • Or with a constructor that accepts sha1, sha256 and md5 hash values as strings (Swift).

    LREmailIdentifier(sha1:"52e17b67fd82b0545bb4fbdc5748ed23104133c7",
                    sha256:"F0E2A21BCF499CBC713C47D8F034D66E90A99F9FFCFE96466C9971DFDC5C9816", 
                    md5:"97dfebf4098c0f5c16bca61e2b76c373")

LRPhoneNumberIdentifier

Caution

Currently, phone numbers are only supported in the U.S..

LRPhoneNumberIdentifier class implements the LRIdentifierData protocol. As an object, LRPhoneNumberIdentifier is used to obtain envelopes as one of the possible parameters of the getEnvelope method.

LRPhoneNumberIdentifier object can be instantiated using one of the following constructors:

  • With a constructor that accepts a phone number as a string (Swift).

    LRPhoneNumberIdentifier("0123456789")
  • Or with a constructor that accepts a SHA1 hash value as a string (Swift).

    LRPhoneNumberIdentifier(sha1:"87acec17cd9dcd20a716cc2cf67417b71c8a7016")

LRCustomIdentfier

Warning

Not Available for All Users

Due to the complexity of the customer ID mapping process, this class is only available for selected publishers who must go through an extensive onboarding process. Please note that you cannot use this API out-of-the-box.

LRCustomIdentifier class implements LRIdentifierData protocol. As an object, LRCustomIdentifier is used to obtain envelopes as one of the possible parameters of the getEnvelope method.

LRCustomIdentifier object can be instantiated using a constructor that accepts customID as a string and the passed value needs to be in the following format ANA_ID:CUSTOM_ID.

ANA_ID represents the Account ID (provided by LiveRamp) whereas CUSTOM_ID represents the custom identifier.

LRCustomIdentifier("54321:abc123")

LRAtsConfiguration

This class is used to configure LRAtsSDK during initialization.

Property Name

Type

Default Value

Description

appId

String

/

App ID obtained from LiveRamp Console.

isTestMode

Bool

False

If set to true, test mode will be enabled in which test data is returned instead of real data from the backend.

logToFileEnabled

Bool

False

If set to true, all log levels will be logged to file in /Documents/ats-sdk-ios/logs directory in the app sandbox.

Table 3.


LREvent

SDK events are defined with LREvent enum.

Case

Description

loading

Loading event is dispatched when the SDK starts initializing.

ready

Ready event is dispatched when the SDK initialization process is successfully completed.

reset

Reset event is dispatched when the SDK has been reset.

disabled

Disabled event is dispatched when the SDK has been disabled.

LRError

The SDK error states are defined with LRError enum. SDK returns the standard Error types. To get more information, you can cast the error to LRError.

Case

Description

notInitialized

The SDK is not initialized.

missingAppId

The Config ID is either empty or expired. You must verify that you provided a valid Config ID from Console and that your subscription for the ATS Mobile SDK is still active.

fetchingConfigurationFailed

The fetching of LRAtsConfiguration is failed for the given appID (Config ID).

noConsent

There is no consent from the user.

atsDisabledInCountry

The country is not listed in atsEnabledCountries in LRAtsConfiguration. To add more countries to your ATS configuration, see Configure ATS Placement.

sdkIsNotReady

SDK status is not ready.

sdkIsDisabled

SDK is disabled.

LRStatus

Status of the SDK is defined with LRStatus enum.

Case

Description

notInitialized

The SDK is not initialized.

loading

The SDK is in the process of initialization.

ready

The SDK is initialized and ready to use.

disabled

The SDK is disabled.

error

The SDK is in an error state.