iOS App Implementation (SDK)

Introduction

Overview

InMobi CMP empowers site and app owners to efficiently handle consent across diverse devices and environments, including iOS. InMobi CMP strictly adheres to the IAB TCF v2.2 standard.

System Requirements

Ensure a minimum iOS version of 11.0 or above for seamless operation.

User Interface (UI)

The CMP's User Experience (UX) is seamlessly integrated within a viewController, presenting a user-friendly overlay on top of the rootViewController of your application.

Data Management

The IAB TCF v2 mobile specifications securely store all consent data, utilizing UserDefaults for robust data management.

UI customisation

We have UI customization capabilities within our  SDK. This feature empowers developers to tailor color schemes and font styles for all UI components used in the InMobi CMP. This ensures seamless integration with the host application's UI style. For more information on customizing styles, see UI Customization for Mobile iOS.

InMobiCMP SDK Configuration and Download

Before integrating InMobi CMP into your mobile app, make sure you have followed the instructions on how to protect an app. Once done, click Download SDK

Set up Xcode Project

Option 1: Integration via Cocoapods

  1. If you are not already using Cocoapods, go to your Xcode project directory and initialize the pod using the following command in the terminal:

    pod init
    
  2. Podfile should be generated as a result of Step 1. Open the podfile and add InMobiCMP pod as shown below:

    target 'InMobiCMPExample' do
      use_frameworks! 
    
      # Pods for InMobiCMPExample
      pod 'InMobiCMP', '1.2.1' 
    
    end
    
  3. Once you have added it to the pod file, run the command below to complete the task of installing the dependency.

    pod update
    
  4. Open the .xcworkspace file to access your project.

Option 2: From Downloaded Zip

  1. From your XCode project, select the top (blue) project file from the left file pane.

  2. On the General tab, find the Frameworks, Libraries, and Embedded Content section and click the "+" button.
  3. On the bottom left of the popover, click the Add Other… dropdown, select Add Files…, and select InMobiCMP.framework file.

Integrate InMobi CMP for Mobile Apps

The following methods are supported for integrating InMobi CMP:

  • SDK Integration through Swift
  • SDK Integration through SwiftUI
  • SDK Integration through Objective-C

SDK Integration (Swift)

  1. In your UIApplicationDelegate class, import InMobiCMP using the following statement.
    import InMobiCMP
    	
  2. Initialize CMP: Call ChoiceCmp.shared.startChoice method. This method requires the following parameters:

    • pcode: A unique identifier retrievable from the web portal. For more information, see Find Your P-CODE.
    • delegate: Assign a delegate to receive callbacks.
    • ccpaDelegate (Optional): Assign a CCPA delegate to receive CCPA callbacks.
    • shouldDisplayIDFA (Optional): It displays the tracking permission popup. The default value is set to true. If you don't wish to display the popup, set the value to false.

    Note

    If shouldDisplayIDFA is true, it is imperative to add the NSUserTrackingUsageDescription key to your info.plist. Provide a clear description of how your app will utilize this value.

import UIKit 
import InMobiCMP   

@main 
class AppDelegate: UIResponder, UIApplicationDelegate, ChoiceCmpDelegate, CCPADelegate { 
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 
        ChoiceCmp.shared.startChoice(pcode: "< YOUR PCODE >", delegate: self) 
        return true 
    } 
}
  1. To utilize the functionality, ensure you implement the necessary callbacks. For detailed best practices on callbacks, refer to the next section.
    func didReceiveIABVendorConsent(tcData: TCData, updated:Bool) {  } 
    func didRecieveNonIABVendorConsent(nonIabData: NonIABData, updated:Bool) {  } 
    func didReceiveAdditionalConsent(acData: ACData, updated:Bool) {} 
    func didReceiveCCPAConsent(string: String) { } 
    func cmpDidError(error: Error) { }
    	
  2. It's important to implement a mechanism that allows users to manually trigger the CMP dialog, enabling them to modify their consent preferences at any time. Typically, this feature can be incorporated into a menu, placed alongside your app's privacy policy or other settings.

    Note

    While the startChoice method is designed to display the popup when necessary, and this additional method is specifically used for the on-demand showing of the CMP dialog:

    To open the CMP, call:

    ChoiceCmp.shared.forceDisplayUI()
    

SDK Integration (SwiftUI)

  1. Import InMobiCMP in your App class.
    import InMobiCMP
    	
  2. Initialize InMobi CMP: Call the method ChoiceCmp.shared.startChoice within the active state of the onChange notification of the main WindowGroup. This method anticipates the following:

    Note

    If shouldDisplayIDFA is true, it is imperative to add the NSUserTrackingUsageDescription key to your info.plist. Provide a clear description of how your app will utilize this value.

    import SwiftUI 
    import InMobiCMP  
    
    @main 
    struct ChoiceSwiftUIApp: App { 
        @Environment(\.scenePhase) private var scenePhase     
        var body: some Scene {          
            WindowGroup { 
                ContentView() 
            }.onChange(of: scenePhase) { newScenePhase in 
                if newScenePhase == .active {  
    ChoiceCmp.shared.startChoice(pcode: "< YOUR PCODE >", delegate: ChoiceDelegate()) 
                } 
            } 
        } 
    }
    
    • pcode: A unique identifier retrievable from the web portal. For more information, see Find Your P-CODE.
    • delegate: Assign a delegate to receive callbacks.
    • ccpaDelegate (Optional): Assign a CCPA delegate to receive CCPA callbacks.
    • shouldDisplayIDFA (Optional): It displays the tracking permission popup. The default value is set to true. If you don't wish to display the popup, set the value to false.
  3. To implement the InMobi CMP SDK delegates, follow the instructions:
    1. Create a delegate class that conforms to the ChoiceCmpDelegate protocol.
    2. Implement the required callbacks specified by the protocol.
    import SwiftUI 
    import InMobiCMP 
    
    @main 
    struct ChoiceSwiftUIApp: App { 
        @Environment(\.scenePhase) private var scenePhase 
        var delegate = ChoiceDelegate()      
        var body: some Scene {          
            WindowGroup { 
                ContentView() 
            }.onChange(of: scenePhase) { newScenePhase in 
                if newScenePhase == .active { ChoiceCmp.shared.startChoice(pcode: "< YOUR PCODE >", delegate: delegate) 
                } 
            } 
        } 
    }  
    class ChoiceDelegate: NSObject, ChoiceCmpDelegate, CCPADelegate { 
        func cmpDidLoad(info: InMobiCMP.PingResponse) {          
        }      
        func cmpDidShow(info: InMobiCMP.PingResponse) {          
        }      
        func didReceiveIABVendorConsent(tcData: InMobiCMP.TCData, updated: Bool) { 
            //Use TCData to know the consent information related to IAB vendors 
        }      
        func didReceiveNonIABVendorConsent(nonIabData: InMobiCMP.NonIABData, updated: Bool) { 
            //Use NonIABData to know the consent information related to Non-IAB vendors 
        }      
        func didReceiveAdditionalConsent(acData: InMobiCMP.ACData, updated: Bool) { 
            //Use ACData to know the consent information related to Google vendors 
        }      
        func cmpDidError(error: Error) {          
        }      
        func didReceiveCCPAConsent(string: String) {          
        }           
    }
    

    Note

    The ChoiceCmp maintains a weak reference to the delegate object to prevent retain cycles. Ensure that you retain a reference to the delegate in your code to prevent it from being deallocated.

  4. If shouldDisplayIDFA is true, it's recommended to include NSUserTrackingUsageDescription in your info.plist file. This communicates to users that your app requests their consent for tracking.
  5. Implementing a feature enabling users to trigger the CMP dialog manually is essential. This allows users to modify their consent preferences whenever they choose. Typically, this functionality can be incorporated into a menu alongside your app's privacy policy or other settings. To open the CMP, call:
    ChoiceCmp.shared.forceDisplayUI()
    

    Note

    The startChoice method displays the popup automatically if necessary. The additional method is specifically designed for on-demand popup display.

SDK Integration (Objective-C)

For products utilizing React Native, it's worth noting that the InMobi CMP is fully compatible with Objective-C. Follow the instructions to outline the requirements for integrating the InMobi CMP with React Native:

  1. Import InMobiCMP into your UIApplicationDelegate header file (.h):
#import <InMobiCMP/InMobiCMP.h>
  1. Make your delegate class conform to the ChoiceCmpDelegate protocol, or create a separate delegate class.
@interface AppDelegate : UIResponder <UIApplicationDelegate, ChoiceCmpDelegate, CCPADelegate>

Note

The InMobi CMP maintains a weak reference to the delegate object to prevent retain cycles. Ensure you retain a reference somewhere in your code to prevent it from being deallocated.

  1. Implement the required callbacks.
    - (void)cmpDidErrorWithError:(NSError * _Nonnull)error {}
    - (void)cmpDidLoadWithInfo:(PingResponse * _Nonnull)info {}
    - (void)cmpDidShowWithInfo:(PingResponse * _Nonnull)info {}
    - (void)didReceiveAdditionalConsentWithAcData:(ACData * _Nonnull)acData updated:(BOOL)updated {}
    - (void)didReceiveIABVendorConsentWithTcData:(TCData * _Nonnull)tcData updated:(BOOL)updated {}
    - (void)didReceiveNonIABVendorConsentWithNonIabData:(NonIABData * _Nonnull)nonIabData updated:(BOOL)updated {}
    - (void)didReceiveCCPAConsent:(NSString * _Nonnull)string { }
    	
  2. In your UIApplication delegate's application:didFinishLaunchingWithOptions: method, insert the following code below any rootViewController initialization:
    [[ChoiceCmp shared] startChoiceWithPcode:@"< YOUR PCODE >" delegate: self ccpaDelegate: self shouldDisplayIDFA:false];
    	
  3. If shouldDisplayIDFA is true, you should include the NSUserTrackingUsageDescription in your info.plist file. This communicates to users that your app requests their consent for tracking.
  4. Implementing a mechanism that enables users to trigger the CMP dialog manually is essential. This empowers users to modify their consent preferences whenever they desire. Typically, this functionality can be integrated into a menu alongside your app's privacy policy or other settings. The startChoice method displays the popup automatically if necessary. This additional method is only required for on-demand popup display. To open the CMP, call::
    ChoiceCmp.forceDisplayUI()
    

    At this stage, you have successfully integrated the SDK. The SDK will actively monitor lifecycle events to ensure that consent is consistently available. If, at any point, consent is not found, the CMP will promptly appear to request the user's consent. Each time a user is prompted, the associated callbacks will be triggered.

Implement Delegate

implement all three consent callbacks, even if you haven't configured all the consent features. This ensures comprehensive consent handling and minimizes the risk of overlooking any crucial aspects.

  1. Manage IAB Vendor Compliant Consent: The didReceiveIABVendorConsent callback is triggered upon obtaining user consent for IAB-compliant vendors. You can find a list of IAB-compliant vendors here. Ideally, IAB-compliant mobile frameworks will autonomously incorporate this consent and adjust their configuration accordingly. However, it's worth noting that not all frameworks are IAB-compliant. If you're uncertain, it's advisable to contact your vendor for clarification. In cases where the framework is not compliant, you'll be responsible for handling the consent process yourself. If the framework prescribes a setup method typically called in didFinishLaunchingWithOptions, ensure it is relocated here and executed after verifying the consent. For instance:
    func didReceiveIABVendorConsent(tcData: TCData, updated: Bool) {
        // Use TCData to know the consent information related to IAB vendors
        
        // Use gdprApplies to check if the gdpr applies or not
        print(tcData.gdprApplies)
        
        // Use tcData.vendor.consents to checkout the vendor consents
        print(tcData.vendor.consents)
    }
    

    TCString can also be accessed directly from the UserDefaults using the key IABTCF_TCString.

  2. Manage Non-IAB Vendor Consent: The didRecieveNonIABVendorConsent callback pertains to vendors configured in the Choice Portal and do not automatically validate consent. Here, consent is provided straightforwardly: either a blanket, yes or no. To verify consent, locate the specific vendor by their assigned ID in the CMP Portal using the following method:
    func didReceiveNonIABVendorConsent(nonIabData: NonIABData, updated: Bool) {
        //Use NonIABData to know the consent information related to Non-IAB vendors
        
        // Use gdprApplies to check if the gdpr applies or not
        print(nonIabData.gdprApplies)
        
        // Use nonIabData.nonIabVendorConsents to checkout the vendor consents
        print(nonIabData.nonIabVendorConsents)
        
    }
    	
  3. Manage Google Vendor Consent: Another crucial callback to be mindful of is didReceiveAdditionalConsent. This callback is specifically invoked if you have enabled Google Vendors in the portal. For more information, see GDPR overview and guidance. As with the other callbacks, utilize this callback to handle consent for Google Vendors effectively.
    func didReceiveAdditionalConsent(acData: ACData, updated: Bool) {
        //Use ACData to know the consent information related to Google vendors
        
        // Use gdprApplies to check if the gdpr applies or not
        print(acData.gdprApplies)
        
        // Use acData.additionalVendorConsent to checkout the vendor consents
        print(acData.additionalVendorConsent)
        
     }
    

    While likely not essential for typical usage, additional callbacks are available for debugging or advanced scenarios. One such callback is cmpDidError, which triggers whenever the CMP exits unexpectedly and fails to collect consent.

CCPA Integration

Display CCPA Screen

After successfully initializing the SDK, you can present the CCPA screen by invoking the following method:

Objective-C

[[ChoiceCmp shared] showCCPAWithCcpaDelegate:self];

Swift

ChoiceCmp.shared.showCCPA(ccpaDelegate: self)

Note

To allow users to opt out of selling their data, you must incorporate a UI control into your application with the text "Do not sell my data". This control should trigger an action that launches the CCPA UI.

Receive CCPA Consent String

To receive a callback for the CCPA consent string once the user taps the confirm button, implement the CCPADelegate protocol. You can access the obtained string through UserDefaults using the key IABUSPrivacy_String.

Objective-C

- (void)didReceiveCCPAConsentWithString:(NSString *)string {
    // Use the string for CCPA consent
}

Swift

func didReceiveCCPAConsent(string: String) {
    // Use the string for CCPA consent
}

Find Your P-CODE

To initialize the SDK, you must provide your account's p-code for proper identification. After you log in to the InMobi CMP portal, you can see the p-code at the top right corner of the screen. However, as shown below, you must omit the initial two characters ("p-") when copying the code for use elsewhere.

Displaying IDFA Popup

The CMP provides an option to seamlessly integrate the new native IDFA permission popup (ATTrackingManager), provided the user has been granted permission for the CMP purposes. Presenting the popup right after the CMP offers users more context about the request, potentially leading to higher acceptance rates.

The popup will be triggered if GDPR applies and consent has been obtained, or if GDPR is explicitly stated not to apply.

If your app and associated vendors will never utilize the IDFA, or if you intend to display this popup at a different time, set this option to false.

However, if you choose to set this option to true, ensure you provide a usage description in your Info.plist. To do this, add a new key named NSUserTrackingUsageDescription and furnish it with a concise yet comprehensive description of how the IDFA will be utilized. For instance, "We use this value to help serve you relevant advertising".

On This Page

Last Updated on: 22 Apr, 2024