Skip to content

Installing on Obj C project without CocoaPods

André Herculano edited this page Jun 7, 2019 · 3 revisions

Installing on Obj-C project without CocoaPods

  1. Clone ConsentViewController's repo.
  2. Clone Reachability's repo
  3. Copy the file Sources/Reachability.swift from the Reachability's folder into your project. If you don't have one yet, XCode will prompt you about creating a bridging header. Click on Create Bridging Header. Select Create Bridging Header
  4. Copy the ConsentViewController folder from the ConsentViewController repo to your project. Make sure to select Added folders: Create Groups like shown in the picture below. Select Added Folders: Create Groups
  5. Go to ConsentViewController/Classes/ConsentViewController.swift file and delete the import Reachability statement.
  6. Finally, on your ViewController.m file, #import "YourProjectsProductName-Swift.h"
  7. You may now use ConsentViewController

Code Example

//  ViewController.m

#import "ViewController.h"
#import "ObjCSDKSample-Swift.h"

@interface ViewController ()
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    ConsentViewController *cvc = [[ConsentViewController alloc] initWithAccountId:22 siteName:@"mobile.demo" stagingCampaign:false andReturnError:nil];

    [cvc setTargetingParamString:@"MyPrivacyManager" value:@"true"];

    [cvc setOnMessageReady:^(ConsentViewController * consentSDK) {
        [self presentViewController:consentSDK animated:false completion:NULL];
    }];

    [cvc setOnInteractionComplete:^(ConsentViewController * consentSDK) {
        [consentSDK getCustomPurposeConsentsWithCompletionHandler:^(NSArray<PurposeConsent *>* purposeConsents) {
            NSLog(@"User has given consent to the purposes: %@", purposeConsents);
        }];

        [consentSDK dismissViewControllerAnimated:false completion:NULL];
    }];

    [cvc loadMessage];
}
@end

Troubleshooting

  1. If your project is a framework itself, you'll need to #import "YourProductsName/YourProductsName-Swift.h" (instead of #import "YourProductsName-Swift.h").
  2. If you're not able to import the header mentioned above, make sure your Target's Product Name is defined. Try setting it to the name of your Project. Target Settings
  3. Some people had to set the option Define Modules > YES as well.
  4. If your project's name have spaces in it, substitute them by underscores when importing the header file like #import "My_Project-Swift.h"