1

I use facebook ads in my app and I'm trying to implement the requestTrackingAuthorization, I'm using the latest FB SDK "swift version" and I can not find the code snippet provided by FB guide

import FBSDKCoreKit
import FBAudienceNetwork

// Set the flag as true
FBAdSettings.setAdvertiserTrackingEnabled(true)
// Set the flag as false
FBAdSettings.setAdvertiserTrackingEnabled(false)

what I found instead is:

Settings.isAdvertiserIDCollectionEnabled = Bool

and I'm not sure if it the same or not, I saw this question and none of the solutions worked, my code ended up like this:

import FBAudienceNetwork
import FBSDKCoreKit

ATTrackingManager.requestTrackingAuthorization { status in
        switch status {
        case .notDetermined:
            break
        case .restricted:
            Settings.isAdvertiserIDCollectionEnabled = false
            Settings.isAutoLogAppEventsEnabled = false
            
        case .denied:
            Settings.isAdvertiserIDCollectionEnabled = false
            Settings.isAutoLogAppEventsEnabled = false
            
        case .authorized:
            Settings.isAdvertiserIDCollectionEnabled = true
            Settings.isAutoLogAppEventsEnabled = true
            
        @unknown default:
            Settings.isAdvertiserIDCollectionEnabled = false
            Settings.isAutoLogAppEventsEnabled = false
        }
    }

so:

1- why I can not find setAdvertiserTrackingEnabled in FBAdSettings neither Settings

2- is isAdvertiserIDCollectionEnabled same as setAdvertiserTrackingEnabled ?

  • 1
    I got from [this](https://stackoverflow.com/questions/64791812/ios-14-get-user-consent-with-facebook-sdk) correct answer that the import was the problem for me. You need to import `import FBSDKCoreKit.FBSDKSettings` (and have at least version 8.0.0 I think). – Daniela P. Riesgo Mar 12 '21 at 18:51

2 Answers2

2
  1. You have to import the FBAudienceNetwork library

In Objective-C

#include <FBAudienceNetwork/FBAdSettings.h>

In Swift

import FBAudienceNetwork
  1. They are not the same, according to the FB Documentation

isAdvertiserIDCollectionEnabled : Controls the access to IDFA If not explicitly set, the default is true

setAdvertiserTrackingEnabled : This allows you to inform Audience Network whether to use the data to deliver personalized ads

DJTano
  • 1,055
  • 12
  • 12
0

For anybody trying to implement this without the need of FBAudienceNetwork isAdvertiserTrackingEnabled is now inside shared (swift) or sharedSettings (objective c) of FBSDKSettings. In my case, in order to implement it on a react native app, I needed:

#import <FBSDKCoreKit/FBSDKSettings.h>
...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [FBSDKSettings.sharedSettings setAdvertiserTrackingEnabled:YES];
}

For swift it would be:

Settings.shared.isAdvertiserTrackingEnabled = true