【问题标题】:Interstitial iAd fails in landscape/horizontal (Spritekit)插页式 iAd 在横向/横向 (Spritekit) 中失败
【发布时间】:2015-11-07 14:11:18
【问题描述】:

您好 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 来跟踪被调用的内容以及一个布尔值 adShowing,它根据广告的状态而变化。运行应用程序并初始化 loadInterstitialAd 后,我注意到 adShowing bool 会变为 true,几秒钟后会经过 "didFailWithError"

会出现在控制台中,表明广告未能显示,这告诉我广告只能在纵向上工作,至少在我的设置下。有谁知道我可以做些什么来更改我的代码以使广告在水平/横向模式下工作?

亲切的问候 瑞恩

编辑 经过相当多的测试,我敢说出来,搞砸了。我注意到该广告有时确实有效,但很少见 :)

【问题讨论】:

    标签: ios objective-c sprite-kit iad landscape


    【解决方案1】:

    在视图控制器中你的游戏场景出现添加

    [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];

    【讨论】:

    • 感谢老兄的回复!我现在在该行上收到以下错误(在运行应用程序之前 - 显示在 Xcode 警告部分中)No visible @interface for 'GameScene' declares the selector 'setInterstitialPresentationPolicy:'
    • 不要直接放在游戏场景中。把它放在呈现场景的视图控制器中。如果你使用的是 Xcode 中的 sprite kit 模板,它被称为 GameViewController。
    • 我把它放在游戏视图控制器中,我没有收到错误但是当我运行它时,我仍然收到我最初收到的失败消息。
    • 我还没有尝试过,但我今晚回来时会看看,并告诉你结果! :)
    • 嘿伙计!好的,我刚回来并尝试实现您的代码。您能否确保其正确并尝试更好地解释它,这似乎没有多大意义。谢谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多