Hello Stackoverflow用户,我再次回到我的插页式广告的另一个问题。这是我用来展示广告的代码:
-(void) loadInterstitialAd {
NSLog(@"loadInterstitialAd");
_interstitialAd = [[ADInterstitialAd alloc] init];
_interstitialAd.delegate = self;
adShowing = true;
}
-(void) interstitialAdWillLoad:(ADInterstitialAd *)interstitialAd {
}
-(void) interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {
NSLog(@"interstitialAdDidLoad");
interstitialAdView = [[UIView alloc] init];
interstitialAdView.frame = (self.view.bounds);
[self.view addSubview:interstitialAdView];
[_interstitialAd presentInView:interstitialAdView];
[UIViewController prepareInterstitialAds];
}
-(void) interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd {
NSLog(@"interstitialAdActionDidFinish");
[interstitialAdView removeFromSuperview];
adShowing = false;
}
-(void) interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
// you must take this funcion , because without it ADInterstitial iAd will not work
NSLog(@"didFailWithError");
adShowing = false;
}
-(void) interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd{
// you must take this funcion , because without it ADInterstitial iAd will not work
NSLog(@"interstitialAdDidUnload");
adShowing = false;
}
此代码位于我的GameScene类中。最初我创建了一个新的sprite kit应用程序来测试广告(应用程序是肖像),这很好。我将它移植到我打算发布的应用程序上,该应用程序是水平的,但它不起作用。我设置了一些NSLog来跟踪被调用的内容以及布尔广告,该广告根据广告的状态而变化。在运行应用程序并初始化loadInterstitialAd
之后,我注意到adShowing bool将变为true,几秒钟就会过去,然后
"didFailWithError"
会出现在控制台中,表示广告无法显示,这告诉我广告只能在我的设置中以纵向方式工作。有没有人有想法我可以做些什么来改变我的代码,以便广告在水平/横向模式下工作?
亲切的问候 瑞恩
修改 经过相当多的测试,我敢说,搞砸了。我注意到广告有时会起作用但非常罕见:)
答案 0 :(得分:0)
在视图控制器中,您的游戏场景会显示添加
[self setInterstitialPresentationPolicy:ADInterstitialPresentationPolicyManual];
在viewDidLoad
中您还需要视图控制器来调用
[self requestInterstitialAdPresentation];
因此,您可以使用showInterstitialAd等方法在GameScene.h中创建协议。像:
@protocol GameSceneDelegate <NSObject>
- (void) showInterstitialAd;
@end
向GameScene.h添加委托属性
@property (nonatomic, weak) id <GameSceneDelegate> delegate;
让视图控制器作为它的委托并实现类似的东西并声明它符合GameSceneDelegate协议。
-(void)showInterstitialAd{
[self requestInterstitialAdPresentation];
}
在GameSceneController的viewDidLoad中设置gameScene.delegate = self;
如果要在GameScene中显示添加[self.delegate showInterstitialAd];