The RudderStack iOS SDK lets you specify the user's consent during initialization.
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.
Developing a consent interceptor
- Create a
CustomConsentInterceptor.h
by extendingRSConsentInterceptor
, as shown: - Create a
CustomConsentInterceptor.m
file, as shown:
#import <Foundation/Foundation.h>#import <Rudder/Rudder.h>NS_ASSUME_NONNULL_BEGIN@interface CustomConsentInterceptor : NSObject<RSConsentInterceptor>@endNS_ASSUME_NONNULL_END
#import "CustomConsentInterceptor.h"
@implementation CustomConsentInterceptor
- (nonnull RSMessage *)interceptWithServerConfig:(nonnull RSServerConfigSource *)serverConfig andMessage:(nonnull RSMessage *)message { RSMessage *updatedMessage = message; // Your code return updatedMessage;}
@end
- Create a
CustomConsentInterceptor
file by extendingRSConsentInterceptor
, as shown:
@objcopen 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())
Installing OneTrust consent
- Install
RudderOneTrust
by adding the following line to yourPodfile
:
pod 'RudderOneTrust', '~> 1.0.0'
- Import the SDK, as shown:
@import RudderOneTrust;
import RudderOneTrust
- Finally, add the imports to your
AppDelegate
file under thedidFinishLaunchingWithOptions
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()) }}
Contact us
For more information on the topics covered on this page, email us or start a conversation in our Slack community.