Integration

Installation

Using CocoaPods

  • Add Vectaury dependency to Podfile: pod 'VectauryCMP'

 target 'Exemple' do
   use_frameworks!

   # Vectaury SDK
   pod 'VectauryCMP', '~> 5.0.2'

   target 'ExempleTests' do
     inherit! :search_paths
     # Pods for testing
   end

   target 'ExempleUITests' do
     inherit! :search_paths
     # Pods for testing
   end

 end

Warning

You need to include Swift standard library. Verify that the Build Settings "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES" is YES (Projet -> Chose the target App -> Build Settings).

  • In your shell, run: pod install

Update

Using CocoaPods

  • In your shell, run: pod update
  • You can check the last available version at: Changelog

In your code

1. Init CMP

To do this, call the function VectauryCMP.initWithConf(conf). This function work with a CMPConfiguration object. see the documentation here ...

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let apiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        let language = "en" // Optional : The language of the CMP, by default the language of device
        let logo : UIImage? = UIImage(named: "logo.jpg") // Optional : Logo on privacy notice
        let primaryColor : UIColor? = .blue // Optional : Color of the CMP, it will be repercuted on color title, switch, button, ...
        let subjectToGDPR : Bool? = true // Optional : Force or not to apply CMP, by default if the user are in europe (by ip traking) the CMP will showed else not
        let filter : IndexSet? = IndexSet([1,5,368]) // Optional : Filter the vendors that you use in app. by default All IAB vendors
        let privacyPolicy : String? = "https://www.vectaury.io/en/personal-data" // Optional : A link to your privacy url on privacy notice

        let conf = CMPConfiguration(apiKey: apiKey,
                                    language: language,
                                    logo: logo,
                                    primaryColor: primaryColor,
                                    subjectToGDPR: subjectToGDPR,
                                    filter: filter,
                                    privacyPolicy: privacyPolicy)

        VectauryCMP.initWithConf(conf)
    }
}
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *apiKey = @"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    NSString *lang = @"fr";
    UIImage *logo = [UIImage imageNamed:@"logo.jpg"];
    UIColor *color = [[UIColor alloc]initWithRed:200/255.0 green:100/255.0 blue:50/255.0 alpha:1];
    NSString *subjectToGDPR = @"1";
    NSIndexSet *vendorUsed = [[NSIndexSet alloc]initWithIndex:368];
    NSString *privacyPolicy = @"https://www.vectaury.io/en/personal-data";

    CMPConfiguration *conf = [[CMPConfiguration alloc]initWithObjcApiKey:apiKey
                                                                language:lang logo:logo
                                                                primaryColor:color
                                                                subjectToGDPR:subjectToGDPR
                                                                filter:vendorUsed
                                                                privacyPolicy:privacyPolicy];

    [VectauryCMP initWithConf:conf];
}
@end

Info

We recomand to integrate this method on the applicationDidBecomeActive(_ application: UIApplication) function in Appdelegate to better performance

2. Present CMP

To show the CMP, use VectauryCMP.present() function. The CMP will show one time only. If you call VectauryCMP.present() twice, the second call will have no effect.

VectauryCMP.present() // Show only once 
[VectauryCMP presentWithForce:NO];

To force the reaparition of CMP, use force parameter:

 VectauryCMP.present(force : true) // Show at each call
[VectauryCMP presentWithForce:YES];

3. Get The CMP Result

You can be advice by a delegate when the CMP UI is closed:

import VectauryCMP

class ViewController: UIViewController, VectauryCMPDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        let apiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
        let conf = CMPConfiguration(apiKey: apiKey)
        VectauryCMP.initWithConf(conf)

        VectauryCMP.delegate = self
    }

    func didCMPFinishTask(_ status: Bool) { // Status represente the error status of CMP
        if (!status) {
            let alert = UIAlertController(title: "CMP Error", message: "CMP Error, show logs for more details", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK", style: .default, handler: {action in}))
            self.present(alert, animated: true, completion: nil)
        }
        print("end CMP status \(status)")
    }
}
// ViewController.h


#import <UIKit/UIKit.h>
#import <VectauryCMP/VectauryCMP.h>

@interface ViewController : UIViewController <VectauryCMPDelegate>


@end

// ViewController.m


#import "ViewController.h"
#import <VectauryCMP/VectauryCMP.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *apiKey = @"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    NSString *lang = @"auto";

    CMPConfiguration *conf = [[CMPConfiguration alloc]initWithObjcApiKey:apiKey language:lang logo:NULL primaryColor:NULL subjectToGDPR:NULL filter:NULL privacyPolicy:NULL];

    [VectauryCMP initWithConf:conf];

    [VectauryCMP presentWithForce:NO withNotice:YES];
}

- (void)didCMPFinishTask:(BOOL)status {
    NSLog(@"%d",status);
}

@end