我正在使用我的应用程序,它是使用Sprite Kit构建的。我尝试添加加载广告的功能,但广告未加载。我不确定这是因为我的应用程序尚未生效,我需要打开某种沙盒,或者我是否做错了什么。广告的显示点是从SKScene
调用的,广告显示功能和方法(加载,显示以及委托)位于父UIViewController
中。
以下是将应用从ViewController
引导至SKScene
的代码:
GameViewController *vc = (GameViewController*)self.view.window.rootViewController;
[vc loadInterstitial];
GameViewController
是SKScene
的父视图控制器。以下是GameViewController
中包含的代码:
- (void)loadInterstitial
{
self.interstitialAd =
[[FBInterstitialAd alloc] initWithPlacementID:@"Placement ID"];
self.interstitialAd.delegate = self;
[self.interstitialAd loadAd];
}
- (void)interstitialAdDidLoad:(FBInterstitialAd *)interstitialAd
{
NSLog(@"Interstitial ad is loaded and ready to be displayed");
// You can now display the full screen ad using this code:
[interstitialAd showAdFromRootViewController:self];
}
- (void)interstitialAd:(FBInterstitialAd *)interstitialAd
didFailWithError:(NSError *)error
{
NSLog(@"Interstitial ad is failed to load with error: %@", error);
}
方法interstitialAdDidLoad
未被调用,我也没有收到任何错误。
答案 0 :(得分:1)
当我在loadInterstitial方法中声明FBInterstitialAd实例时,我遇到了没有显示插页式广告的问题。在方法之外移动声明之后,它神奇地起作用了。请在此处查看Facebook Audience网络示例:https://github.com/fbsamples/audience-network-support
答案 1 :(得分:0)
将FBInterstitialAdDelegate
添加到您的GameViewController
界面。