The RudderStack iOS SDK lets you specify the user's consent during initialization.

The RudderStack iOS SDK supports OneTrust consent management from version 1.9.0.

This guide lists the steps to:

  • Develop a consent interceptor for the iOS SDK.
  • Use the interceptor to initialize the SDK once the user gives their consent.
  1. Create a CustomConsentInterceptor.h by extending RSConsentInterceptor, as shown:

  2. #import <Foundation/Foundation.h>
    #import <Rudder/Rudder.h>
    NS_ASSUME_NONNULL_BEGIN
    @interface CustomConsentInterceptor : NSObject<RSConsentInterceptor>
    @end
    NS_ASSUME_NONNULL_END
  3. Create a CustomConsentInterceptor.m file, as shown:

  4. #import "CustomConsentInterceptor.h"
    @implementation CustomConsentInterceptor
    - (nonnull RSMessage *)interceptWithServerConfig:(nonnull RSServerConfigSource *)serverConfig andMessage:(nonnull RSMessage *)message {
    RSMessage *updatedMessage = message;
    // Your code
    return updatedMessage;
    }
    @end
  1. Create a CustomConsentInterceptor file by extending RSConsentInterceptor, as shown:

  2. @objc
    open class OneTrustInterceptor: NSObject, RSConsentInterceptor {
    @objc
    public override init() {
    super.init()
    }
    public func intercept(
    withServerConfig serverConfig: RSServerConfigSource, andMessage message: RSMessage
    ) -> RSMessage {
    let updatedMessage = message
    // Your code
    return updatedMessage
    }
    }

Registering interceptor with iOS SDK

You can register CustomConsentInterceptor with the iOS SDK during its initialization, as shown:

RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
[builder withLoglevel:RSLogLevelDebug];
[builder withDataPlaneUrl:DATA_PLANE_URL];
[builder withConsentInterceptor:[[CustomConsentInterceptor alloc] init]];
[RSClient getInstance:WRITE_KEY config:builder.build];
let builder: RSConfigBuilder = RSConfigBuilder()
.withLoglevel(RSLogLevelDebug)
.withDataPlaneUrl(DATA_PLANE_URL)
.withConsentInterceptor(CustomConsentInterceptor())
RSClient.getInstance(rudderConfig.WRITE_KEY, config: builder.build())
  1. Install RudderOneTrust by adding the following line to your Podfile:
pod 'RudderOneTrust', '~> 1.0.0'
  1. Import the SDK, as shown:
@import RudderOneTrust;
import RudderOneTrust
  1. Finally, add the imports to your AppDelegate file under the didFinishLaunchingWithOptions method, as shown:
[[OTPublishersHeadlessSDK shared] startSDKWithStorageLocation:STORAGE_LOCATION domainIdentifier:DOMAIN_IDENTIFIER languageCode:@"en" params:nil loadOffline:NO completionHandler:^(OTResponse *response) {
if (response.status) {
RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
[builder withLoglevel:RSLogLevelDebug];
[builder withDataPlaneUrl:DATA_PLANE_URL];
[builder withConsentInterceptor:[[OneTrustInterceptor alloc] init]];
[RSClient getInstance:rudderConfig.WRITE_KEY config:builder.build];
}
}];
OTPublishersHeadlessSDK.shared.startSDK(
storageLocation: STORAGE_LOCATION,
domainIdentifier: DOMAIN_IDENTIFIER,
languageCode: "en"
) { response in
if response.status {
let builder: RSConfigBuilder = RSConfigBuilder()
.withLoglevel(RSLogLevelDebug)
.withDataPlaneUrl(DATA_PLANE_URL)
.withConsentInterceptor(OneTrustInterceptor())
RSClient.getInstance(rudderConfig.WRITE_KEY, config: builder.build())
}
}
Make sure you load the SDK only after initializing the OneTrust SDK successfully.

Contact us

For more information on the topics covered on this page, email us or start a conversation in our Slack community.

On this page