【问题标题】:Interstitial iAD: How to detect closing on iOS 8?插页式 iAD:如何在 iOS 8 上检测关闭?
【发布时间】:2014-12-01 15:48:08
【问题描述】:

我们在关卡之间展示插页式 iAd。由于 iAd 似乎需要相当多的内存(我们过去在显示时收到很多内存警告并经历了一些崩溃),我们不会在插页式广告关闭之前加载新视图(因此,我们首先卸载游戏视图,然后我们显示插页式广告,然后我们加载游戏视图)。

为此,我们使用了旧的/已弃用的方式来显示插页式广告:

  1. 分配 ADInterstitialAd 并设置委托

    _interstitial = [[ADInterstitialAd alloc] init];
    _interstitial.delegate = self;
    
  2. 准备就绪后,在某个视图控制器中展示广告:

    [_interstitial presentFromViewController:_rootViewController];
    
  3. 监听委托方法以检测用户何时关闭插页式广告:

    - (void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd
    {
        [self proceedToNextLevel];
    }
    

这曾经在 iOS 7 中有效。然而,在 iOS8 中,虽然大多数委托函数都被调用,但 interstitialAdActionDidFinish 不会被调用(interstitialAdDidUnload 会被调用,但只是在 5 分钟后)。

因此,似乎有一些通过 UIViewController 上的类别显示插页式广告的新方法:https://developer.apple.com/library/ios/documentation/iAd/Reference/UIViewController_iAd_Additions/index.html#//apple_ref/occ/instm/UIViewController/shouldPresentInterstitialAd

所以新的方法是:

  1. 通过静态方法调用准备广告:

    [UIViewController prepareInterstitialAds];
    
  2. 准备就绪后,请求展示广告:

    _rootViewController.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;
    [_rootViewController requestInterstitialAdPresentation];
    

这确实显示了插页式广告 - 但是,由于不再有委托,因此无法判断用户何时关闭插页式广告。

所以问题是:在 iOS 8(也兼容 iOS 7)上,我们如何判断用户何时关闭了插页式广告?

//编辑: 我也试过查询

    viewController.isPresentingFullScreenAd

重复使用计时器,但虽然这适用于 iOS 7,但在 iOS 8 上,该属性始终返回 true,即使在用户关闭插页式广告后也是如此

【问题讨论】:

    标签: objective-c ios8 iad interstitial


    【解决方案1】:

    当一个插页式 iAd 关闭时,会在您的 VC 中调用 viewDidAppear。

    这是我的实现方式...

    当我想展示广告时,我从我的 SKScene 调用以下代码。

        MyScene.m
    
        if ([viewController showIAd]) // attempting to show an ad
        {
            NSLog(@"showIAd returned YES, ad shown");
            // Do nothing.  Wait for viewDidAppear to be called.
        }
        else
        {
            // No ad was ready, do what needs to happen after ad.
        }
    

    显示 iAd 时,我设置了一个名为 currentShowingAnIAd 的 BOOL。当 viewDidAppear 运行时,它知道它是从广告返回的。

    viewController.m
    
    -(void)viewDidAppear:(BOOL)animated
    {
        NSLog(@"viewDidAppear");
    
        if (self.currentlyShowingAnIAd)
        {
            self.currentlyShowingAnIAd = NO;
    
            // Do what needs to happen after ad.
        }
    }
    
    -(BOOL)showIAd
    {
        NSLog(@"showIAd method run");
        self.currentlyShowingAnIAd = [self requestInterstitialAdPresentation];
        return self.currentlyShowingAnIAd;
    }
    

    希望这会有所帮助:)

    【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多