iOS: Basic implementation

iOS: Basic implementation

UIKit implementation

To implement the iOS version of SibboCMP you must follow the following steps:
  1. Open the framework we provide in a code editor. There are two main directories:
    1. ios-arm64_armv7 -> this is the directory to be used in production
    2. ios-arm64_i386_x86_64-simulator -> this is the directory to be used in the XCode simulator
  2. Open the file ios-arm64_armv7/SibboFramework.framework/index.html.
  3. Replace {{URL}} with the URL we provided.
  4. Open the file ios-arm64_i386_x86_64-simulator/SibboFramework.framework/index.html.
  5. Replace {{URL}} with the URL we provided.
  6. Open the project in XCode and add the framework to the Frameworks, Libraries, and Embedded Content section of the General tab in the chosen Target.
  7. Check that it appears as Embed & Sign
  8. Import the library in the project with the following import:
    1. import SibboFramework
  9. To start the library, we instantiate the SibboCMP shared object with:
    1. let sibboCMP = SibboViewModel.shared

With the instantiated shared we can interact with the library in the following way: Always at the start of the application, from the viewDidLoad method you have to fire the showConsentTool method, passing it the viewController from which you want to launch it, so that it shows the CMP interface if it is necessary. The completion handler must also be managed in the call, which will return whether or not the CMP has been displayed. To do this, do the following:
  1. let sibboCMP = SibboViewModel.shared                                                                                                                                            

  2. sibboCMP.showConsentTool(fromController: self, completion: { showed in
  3.     if showed {
  4.         print ("CMP shown")
  5.     } else {
  6.         print ("CMP not shown")
  7.     }

The dataSavedCallback parameter is an optional block of code that will be executed after the data has been saved. This block does not receive any parameters and does not return any value. You can use this block to perform any actions you need after the data has been saved, such as updating the user interface, sending a notification, etc.

To use the dataSavedCallback in UIKit, follow these steps:

  1. 1.   sibboCMP.showConsentTool(fromController: self, forceOpen: true, completion: { showed in                                                 

    2.       if showed {

    3.           print ("CMP shown")

    4.       } else {

    5.           print ("CMP not shown")

    6.       }

    7.   }, dataSavedCallback: {

    8.           // This block is executed after the consent data has been successfully saved

    9.           // You can perform any actions here that should take place after data is saved

    10.        print("Data has been saved successfully.")

    11.    }

    12.})


The dataSavedCallback value is optional.
  1. 1.   sibboCMP.showConsentTool(fromController: self, forceOpen: true, completion: { showed in                                                 

    2.       if showed {

    3.           print ("CMP shown")

    4.       } else {

    5.           print ("CMP not shown")

    6.       }

    7.   }, dataSavedCallback: {

    8.           // This block is executed after the consent data has been successfully saved

    9.           // You can perform any actions here that should take place after data is saved

    10.        print("Data has been saved successfully.")

    11.    }

    12.})


It is mandatory to add to the app that hosts the CMP, a link or button with the text Cookies or Cookie Configuration, which triggers the 
  1. sibboCMP.showConsentTool( fromController: self, forceOpen: true, completion: { showed in }, dataSavedCallback: {} )
method, this will refloat the CMP.


SwiftUI implementation

To implement the iOS version of SibboCMP you must follow the following steps:

  1. Open the framework we provide in a code editor. There are two main directories:
    1. ios-arm64_armv7 -> this is the directory to be used in production
    2. ios-arm64_i386_x86_64-simulator -> this is the directory to be used in the XCode simulator
  2. Open the file ios-arm64_armv7/SibboFramework.framework/index.html.
  3. Replace {{URL}} with the URL we provided.
  4. Open the file ios-arm64_i386_x86_64-simulator/SibboFramework.framework/index.html.
  5. Replace {{URL}} with the URL we provided.
  6. Open the project in XCode and add the framework to the Frameworks, Libraries, and Embedded Content section of the General tab in the chosen Target.
  7. Check that it appears as Embed & Sign
  8. Import the library in the project with the following import:
    1. import SibboFramework
  9. Within your view, create a state variable called "isPresented" that will control whether the consent tool is displayed or not.
    1. @State private var isPresented = true.
    2. In the body of your view, use the "fullScreenCover" modifier to present the consent tool as a full-screen view. To control whether the view is shown or not, bind "isPresented" to "fullScreenCover".

struct ContentView: View {

    @State private var isPresented = true

 

    var body: some View {

        Text("SibboFramework")

            .fullScreenCover(isPresented: $isPresented) {

                SibboViewModel.shared.consentToolViewSwiftUI(forceOpen: true) { showed in

                    if showed {

                        print("Mostrado!!!")

                    } else {

                        print("No mostrado!!!")

                    }

                    isPresented = false

                }

                .edgesIgnoringSafeArea(.all)

            }

    }

}

The first parameter is a boolean flag that, if true, will force the opening of the consent tool. The second parameter is a completion block that will be executed when the function finishes. This block receives a boolean value indicating whether the consent tool was shown or not.

When the consent tool is closed, isPresented is set to false to hide the view.


For the integration of the CMP with programmatic advertising, see the section iOS methods.
To implement the CMP on iOS you must send us the Bundle Id of the app. In this way we can include it in our whitelist. Otherwise, at the end of the deployment process, you will receive a message in the XCode console that the application is not validated.


Managing Development and Production Environments in Swift with Preprocessing Flags

In this Swift code, the transition from a development to a production environment is managed by using Swift's preprocessing feature. When you are building your project in Xcode, you can define various build configurations. Here, a preprocessing flag named DEBUG is defined and active when you are in a development environment. This flag is used to determine the value of the Environment enum that should be used.
  1. #if DEBUG
  2. private let environment: Environment = .development

  3. #else
  4. private let environment: Environment = .production

  5. #endif

This means that when you are compiling and running your project in a development environment (likely on a simulator or on a device through Xcode), the environment variable will be set to .development. Conversely, when you compile your project for a production environment (likely when you are preparing a build for distribution on the App Store or to end-users), the DEBUG flag will not be defined. Consequently, the environment variable will be set to .production.

This setup is a common practice in iOS development to differentiate between different environments at compile-time. It allows developers to use different settings or configurations based on whether they're in the process of developing and testing their app, versus when they're preparing a release version for distribution. 

For example, you might want to use different server URLs, enable additional logging, or use different app settings when in a development environment compared to a production environment. The DEBUG flag and the resulting Environment enum value allow you to make these adjustments automatically based on the current build configuration.