Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No such module 'AppTrackingTransparency' Error

Tags:

xcode

ios

I am trying to update my Google AdMob account as Apple announced a new transparency framework that requires changes to the iOS apps with the release of iOS 14. I updated my Google AdMob pod to the latest version (7.64.0). But, when I am trying to use the following code in the App Delegate:-

import AppTrackingTransparency
import AdSupport
...
func requestIDFA() {
    ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
    // Tracking authorization completed. Start loading ads here.
    // loadAd()
    })
}

I get the following error:-

No such module 'AppTrackingTransparency'

Any help would be highly appreciated!!🙏

like image 966
Pressing_Keys_24_7 Avatar asked Aug 21 '20 03:08

Pressing_Keys_24_7


2 Answers

objective-c :

#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>

extern "C" void RequestIDFA()
{
    if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
        }];
    } else {
    }
}

like image 63
Phạm Ân Avatar answered Oct 18 '22 20:10

Phạm Ân


it's only available starting from Xcode 12, including beta version.

and to use it

import AppTrackingTransparency
import AdSupport

if #available(iOS 14, *) {
   ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
  // Load ads here 
   })
} else {
  // Load ads here 
}

Exmaple for RewardedVideoAdsManager

class RewardedVideoAdsManager: GADRewardedAd {


static let shared = RewardedVideoAdsManager()

var rewardedAd: GADRewardedAd?

func createAndLoadRewardedAd(unitId: String) -> GADRewardedAd? {
    rewardedAd = GADRewardedAd(adUnitID: unitId)
    let myRequest = GADRequest()
    rewardedAd?.load(myRequest) { error in
        if let error = error {
            print("Loading failed: \(error)")
        } else {
            print("Loading Succeeded")
        }
    }
    return rewardedAd
}

}

And in my AppDelegate or First main screen

    if #available(iOS 14, *) {
        ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
            RewardedVideoAdsManager.shared.rewardedAd = RewardedVideoAdsManager.shared.createAndLoadRewardedAd(unitId: "ca-app-pub-8175294120313121/4011630802")
        })
    } else {
        RewardedVideoAdsManager.shared.rewardedAd = RewardedVideoAdsManager.shared.createAndLoadRewardedAd(unitId: "ca-app-pub-8175294120313121/4011630802")
    }
like image 20
Ahmed Safadi Avatar answered Oct 18 '22 19:10

Ahmed Safadi