如何使Facebook的广告生活?

我在iOS应用中添加了Facebook受众群体networking,以实现原生广告的整合。 一切工作正常,但只有testing广告。

我添加了testDeviceKey来显示广告,如果我试图删除这个,那么没有广告显示,这也使我感到困惑。 我的代码是 –

@implementation AdFeedsView FBNativeAd *nativeAd; static NSString *adPlacementId = @"xxxxxxxxx"; - (void)showNativeAd:(UIViewController *)vc { nativeAd = [[FBNativeAd alloc] initWithPlacementID:adPlacementId]; nativeAd.delegate = self; NSLog(@"isTestMode1: %d",[FBAdSettings isTestMode]); NSString *testDeviceKey = [FBAdSettings testDeviceHash]; if (testDeviceKey) { [FBAdSettings addTestDevice:testDeviceKey]; } [nativeAd loadAd]; } 

所以我只想问一下,在我的代码中需要做些什么改变才能看到正确的广告,而不是在我的实时应用程序中testing广告?

最后我find解决办法。 其实我已经添加了代码

 NSString *testDeviceKey = [FBAdSettings testDeviceHash]; if (testDeviceKey) { [FBAdSettings addTestDevice:testDeviceKey]; } 

即将所有有源器件作为testing设备,因此只有testing广告。 我已经删除了现场版本,并包括代码

 [FBAdSettings clearTestDevices]; 

我们也可以做

 if ([FBAdSettings isTestMode]) { [FBAdSettings clearTestDevice:[FBAdSettings testDeviceHash]]; } 

我对testing模式有一个错误的认识。 我认为当我的应用程序生效时它将是错误的,但实际上它只是告诉设备已经添加为testing设备。

Swift 3

此代码将确保您的testing广告显示在testflight或模拟器/设备上,并确保在您向app store发布广告时,您的广告将显示为实时广告,并且testing设备将被清除。

如果你在很多地方有你的广告,你可以把这个代码放在AppDelegate中

 import FBAudienceNetwork private func facebookAdsControl() { #if RELEASE self.clearTestDevicesForFacebookAds() #else self.addTestDevicesForFacebookAds() #endif } ///remove for live mode private func addTestDevicesForFacebookAds(){ let key = FBAdSettings.testDeviceHash() FBAdSettings.setLogLevel(FBAdLogLevel.Log) FBAdSettings.addTestDevice(key) } ///add for live mode private func clearTestDevicesForFacebookAds() { FBAdSettings.clearTestDevices() } 

调用didFinishLaunchingWithOptions的: facebookAdsControl()

您也可以在有广告的代码中调用此代码,但请确保在adView.load()之前调用此代码。

为了使用这个macros,你必须在Build Settings中将这些标志添加到你的Swift Flags中

我希望这可以帮助别人,因为我发现Facebook文件不是很清楚。