简体   繁体   English

非页内广告iAd在横向/水平方向(Spritekit)失败

[英]Interstitial iAd fails in landscape/horizontal (Spritekit)

Hello Stackoverflow users, Im back again with another problem with my interstitial ads. 您好,Stackoverflow用户,我再次插页式广告遇到了另一个问题。 This is the code I am using to display ads: 这是我用来展示广告的代码:

-(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;
}

This code is in my GameScene class. 这段代码在我的GameScene类中。 Originally I created a new sprite kit application for testing ads(the application was portrait) and this worked fine. 最初,我创建了一个新的Sprite Kit应用程序来测试广告(该应用程序为纵向),并且运行良好。 I ported it over onto the application I intended to publish which was horizontal and it didn't work. 我将其移植到了我打算发布的应用程序上,该应用程序是水平的,但是没有用。 I set up some NSLog's to track what was being called along with a boolean adShowing which changes depending on the state of the ad. 我设置了一些NSLog来跟踪被调用的内容以及一个布尔adShowing,该布尔showShowing根据广告的状态而变化。 After running the application and initialising loadInterstitialAd I noticed that the adShowing bool would become true, a couple of seconds would pass and then "didFailWithError" 运行应用程序并初始化后loadInterstitialAd我注意到adShowing布尔将成为真正的,几秒钟会通过,然后"didFailWithError"

would appear in the console indicating that the ad had failed to display which tells me that ads only work in portrait at least with my set up. 会出现在控制台中,表明广告未能展示,这告诉我广告至少在我的设置下只能以纵向运行。 Does anyone have ideas what I can do to change my code so that ads work in horizontal/landscape mode? 有谁知道如何更改代码以使广告在水平/横向模式下工作?

Kind Regards Ryan 亲切的问候莱恩

EDIT After quite a lot of testing and dare I say it, messing about. 编辑经过大量的测试,我敢说,一团糟。 I have noticed that the ad does work sometimes but very rarely :) 我注意到该广告有时可以运行,但很少使用:)

In the view controller your game scene appears add 在视图控制器中,您的游戏场景出现添加

[self setInterstitialPresentationPolicy:ADInterstitialPresentationPolicyManual];

in viewDidLoad 在viewDidLoad中

You also need the view controller to call 您还需要视图控制器来调用

[self requestInterstitialAdPresentation];

So you can create a protocol in GameScene.h with a method like showInterstitialAd. 因此,您可以使用诸如showInterstitialAd之类的方法在GameScene.h中创建协议。 Like: 喜欢:

@protocol GameSceneDelegate <NSObject>
- (void) showInterstitialAd;
@end

Add a delegate property to GameScene.h 将委托属性添加到GameScene.h

@property (nonatomic, weak) id <GameSceneDelegate> delegate;

Have the view controller as it's delegate and implement something like and declare it conforms to the GameSceneDelegate protocol. 将视图控制器作为其委托,并实现类似的东西并声明它符合GameSceneDelegate协议。

-(void)showInterstitialAd{
  [self requestInterstitialAdPresentation];
}

In the viewDidLoad of GameSceneController set the gameScene.delegate = self; 在GameSceneController的viewDidLoad中设置gameScene.delegate = self;

When you want to show the add in GameScene call [self.delegate showInterstitialAd]; 当您想显示GameScene中的添加项时,请调用[self.delegate showInterstitialAd];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM