Getting Started with iOS

You can add the SDK to the project by using the Cocoapods. CocoaPods is a dependency manager for Swift Cocoa projects. Cocoapods provides a fast, simple way to install and keep up with the latest updates to our library.

For more information on Cocoapods, see https://cocoapods.org/.

Step 1 Add the following library to your Podfile:

pod 'ConsentViewController'

Step 2 Open the command prompt and type the following:

pod install

Step 3 Press enter

You can manually add the SDK to the project.

Note: In the manual process, we do not create framework for Sourcepoint SDK. We manually add the Sourcepoint SDK into iOS based applications.

To manually add the SDK to the project:

  1. Download the Sourcepoint iOS SDK using the https://github.com/SourcePointUSA/ios-cmp-app/ link.

  2. Download the Reachability Framework iOS SDK using the https://github.com/ashleymills/Reachability.swift/ link.

  3. Drag and drop the Reachability.swift file from Reachability.swift-master > Sources folder into your code base.

  4. Drag and drop the ConsentViewController folder from ios-cmp-app-master folder into your code base.

  5. In Xcode, in the Choose options for adding these files: dialog box, select Copy items if needed to copy the downloaded SDK files to the code base and click Finish.

  1. In your code base, access the ConsentViewController file and delete the Import Reachability line.

  2. In your code base, access the ConsentViewController and delete the .gitkeep file.

Note: For Objective-C, in Swift Compiler – Language Setting, add Swift Language Version and set its value to Swift 4.2.

  1. Run the application.

The SDK is integrated into application. You are now able to initialize the SDK.

You must initialize the SDK for it to start working. For this, you need to initialize ConsentViewController. When you are adding the SDK to the project using Cocoapods, import ConsentViewController in ViewController for initializing the SDK.

Initialize with required and optional parameters

To initialize ConsentViewController with both the required and optional parameters, call the following method. The example below adds the ConsentViewController to an app's ViewController class.

The three variables that should get set are accountId (in this example account 22 is the main Sourcepoint demo account), the siteName (this corresponds to the site name entered into the Sourcepoint UI for the app) and the stagingCampaign variable (this should always be set to false unless instructed by your Sourcepoint account team for troubleshooting purposes).

import UIKit
import ConsentViewControllerclass ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let cvc = try! ConsentViewController.init(accountId: 22, siteName:
"mobile.demo", stagingCampaign: false)
cvc.setTargetingParam(key: "CMP", value: "true")
cvc.onMessageReady = { controller in
self.present(controller, animated: false, completion: nil)
}
cvc.onInteractionComplete = { controller in
controller.getCustomVendorConsents(completionHandler: { vendorConsents in
guard let vendorConsents = vendorConsents else { return }
vendorConsents.forEach({ consent in print("Consented to \(consent)")})
})
self.dismiss(animated: false, completion: nil)
}
cvc.loadMessage()
}
}

The functions to access the consent data are executed inside of the onInteractionComplete event.

The functions in this section of the document explain how to retrieve consent information for both IAB and Non-IAB vendors and purposes. Consent data is stored and can be retrieved from UserDefaults in iOS.

Retrieve Standard IAB Consent String

The following method is used to retrieve the standard IAB Consent string from UserDefaults.

public func getIABVendorConsents(_ forIds: [Int]) throws -> [Bool] {
let storedConsentString = UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_CONSENT_STRING) ?? "" return results
}
  1. This function should be called either during the onInteractionComplete callback or after it has returned.

  2. Returns a IAB consent string that can be passed as a daisybit parameter in an OpenRTB bid request.

Get IAB Consent Data The getIABVendorConsents method is used to retrieve the IAB consents given to each vendor ID in the array passed as a parameter.

public func getIABVendorConsents(_ forIds: [Int]) throws -> [Bool] {
}

The following provides information about the precondition, parameter, and return type for the above method.

  1. This function should be called either during the onInteractionComplete callback or after it has returned.

  2. The function gets passed an array of vendor IDs.

  3. The function returns an array of Boolean values indicating whether the user has given consent to the corresponding vendor.

Get IAB Purpose Data

The following method is used to check whether consent was provided for the IAB purposes passed as parameter.

public func getIABPurposeConsents(_ forIds: [Int8]) throws -> [Bool] {
}

The following provides information about the precondition, parameter, and return type for the above method.

  1. This function should be called either during the onInteractionComplete callback or after it has returned.

  2. This function is passed an array of purpose IDs.

  3. This function returns an array of Boolean values indicating if the user has given consent to the corresponding purpose.

Check Non-IAB consent

The following method is used to check whether consent was provided to the non-IAB consents passed as parameter.

public func getCustomVendorConsents() throws -> Array<VendorConsent> {}

The following provides information about the precondition, parameter, and return type for the above method.

  1. This function should be called either during the onInteractionComplete callback or after it has returned.

  2. The function gets passed an array of vendor IDs.

  3. The function returns an array of Boolean values indicating whether the user has given consent to the corresponding vendor.

Check Non-IAB purposes

The following method is used to check whether consent was provided to the non-IAB purposes passed as parameter.

public func getCustomPurposeConsents() throws -> [PurposeConsent] {}

The following table provides information about the precondition, parameter, and return type for the above method.

  1. This function should be called either during the Callback, onInteractionComplete, or after it has returned.

  2. The function gets passed a purpose ID.

  3. The function returns a Boolean value as to whether or not the user has consented to the purpose.

To display the proper message and privacy manager within the app, the app needs to be linked to your account in the Sourcepoint UI and a "site" within the UI. This is done with when the ConsentViewController.init(accountId: 22, siteName: "mobile.demo", stagingCampaign: false) line of code. In this example the accountId of 22 corresponds to the "Account ID" found in the account page in the Sourcepoint UI (see screenshot below).

The siteName parameter is a name defined in the site section of the Dialogue portion of the Sourcepoint UI. The name is arbitrary and just needs to be a name that makes sense to you. Site names such as ios.app and or android.app are both valid names.

Some of the functions above require using IDs retrieved from the Sourcepoint UI. In particular, the functions for retrieving consent data on Non-IAB vendors and purposes.

To get a particular vendor or purpose ID please do the following:

  1. Go to the Vendor List window of the Consent section of the Sourcepoint UI.

  2. Click on the vendor or purpose for which you are getting the ID.

  3. Retrieve the ID from window (see screenshot below).

This is the ID that is used in functions designed to get the consent status of a particular vendor or purpose for a user.

If you have any additional questions, please contact your Sourcepoint account manager.