插页式iAD:如何在iOS 8上检测关闭? [英] Interstitial iAD: How to detect closing on iOS 8?

查看:146
本文介绍了插页式iAD:如何在iOS 8上检测关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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


  1. 分配ADInterstitialAd并设置委托

      _interstitial = [[ADInterstitialAd alloc] init]; 
    _interstitial.delegate = self;


  2. 准备好后,在某个viewcontroller中显示广告:

      [_ interstitial presentFromViewController:_rootViewController]; 


  3. 听取委托方法以检测用户何时关闭插页式广告:

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


这曾经工作过然而,在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上,即使在用户关闭插页式广告后,该属性也始终返回

解决方案

当插页式广告联盟关闭时,会在您的VC中调用viewDidAppear。



以下是我的实现方式......



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

  MyScene.m 

if([viewController showIAd])//试图显示一个n ad
{
NSLog(@showIAd返回YES,广告显示);
//什么都不做。等待viewDidAppear被调用。
}
其他
{
//没有广告准备就绪,做广告之后需要做的事情。
}

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

  viewController.m 

- (void) viewDidAppear:(BOOL)动画
{
NSLog(@viewDidAppear);

if(self.currentlyShowingAnIAd)
{
self.currentlyShowingAnIAd = NO;

//做广告之后需要做的事情。
}
}

- (BOOL)showIAd
{
NSLog(@showIAd method run);
self.currentlyShowingAnIAd = [self requestInterstitialAdPresentation];
返回self.currentlyShowingAnIAd;
}

希望这会有所帮助:)


We show interstitial iAds between levels. Since iAds appear to require quite a bit of memory (we used to receive many memory warnings when they are shown and experienced some crashes), we do not load the new view before the interstitial has been closed (so, we first unload the game view, then we show the interstitial, then we load the game view).

For this, we used the old/deprecated way of showing interstitials:

  1. allocate ADInterstitialAd and set delegate

    _interstitial = [[ADInterstitialAd alloc] init];
    _interstitial.delegate = self;
    

  2. when ready, present Ad in some viewcontroller:

    [_interstitial presentFromViewController:_rootViewController];
    

  3. listen to delegate methods to detect when the user closed the interstitial ad:

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

This used to work in iOS 7. In iOS8 however, while most of the delegate functions get called, interstitialAdActionDidFinish does not get called (interstitialAdDidUnload does get called, but only like 5 minutes later).

So, there seems to be some new way of showing interstitial ads through a category on UIViewController: https://developer.apple.com/library/ios/documentation/iAd/Reference/UIViewController_iAd_Additions/index.html#//apple_ref/occ/instm/UIViewController/shouldPresentInterstitialAd

So the new way would be:

  1. prepare ads through static method call:

    [UIViewController prepareInterstitialAds];
    

  2. when ready, request display of ad:

    _rootViewController.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;
    [_rootViewController requestInterstitialAdPresentation];
    

This does show the interstitial - however, since there is no delegate anymore, there is no way of telling when the user closed the interstitial.

So the question is: How on iOS 8 (and also compatible to iOS 7) can we tell when a user closed an interstitial Ad?

//edit: I also tried to query

    viewController.isPresentingFullScreenAd

repeatedly with a timer, but while this works on iOS 7, on iOS 8 the property is always returning true, even after the user closed the interstitial ad

解决方案

When an interstitial iAd closes, viewDidAppear is called in your VC.

Here's how I implement...

I call the following code from my SKScene when I want to show an ad.

    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.
    }

When an iAd is displayed I set a BOOL called currentlyShowingAnIAd. When viewDidAppear runs it knows it's returning from an ad.

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

Hope this helps :)

这篇关于插页式iAD:如何在iOS 8上检测关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆