没有此类模块“ AppTrackingTransparency”错误

时间:2020-08-21 03:33:37

标签: ios xcode

我试图更新我的Google AdMob帐户,因为苹果公司宣布了一个新的透明度框架,该框架要求随着iOS 14的发布而对iOS应用程序进行更改。但是,当我尝试在App Delegate中使用以下代码时:-

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

我收到以下错误:-

No such module 'AppTrackingTransparency'

任何帮助将不胜感激!?

2 个答案:

答案 0 :(得分:12)

仅从Xcode 12(包括beta版)开始可用。

并使用它

import AppTrackingTransparency
import AdSupport

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

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
}

}

在我的AppDelegate或第一个主屏幕中

    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")
    }

答案 1 :(得分:4)

目标-c:

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

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