iAds从后台重新启动应用程序后加载限制(也在iAdSuite中发生)

use*_*853 12 cocoa-touch objective-c iad

我正在尝试将NavigationBanner iAdSuite示例实现到我的项目中,以便我可以AdBannerView跨多个视图控制器共享单个实例,但我不断收到以下错误:

错误域= ADErrorDomain代码= 2"操作无法完成.加载受限制

我已将相关代码完全从当前的iAdSuite复制到我自己的应用程序中,并收到此错误.实际上,这个错误在Apple自己的NavigationBanner的iAdSuite示例中是可重复的(这是我试图实现的示例).通过添加以下内容可以看到错误:

NSLog (@"%@",error);
Run Code Online (Sandbox Code Playgroud)

至:

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
Run Code Online (Sandbox Code Playgroud)

要复制问题,iAdSuite请执行以下操作:

  1. 将设备飞行模式设置为开
  2. 从Xcode启动iAdSuite NavigationBanner.这会立即生成错误"ADErrorDomain error 1".
  3. 按设备上的主屏幕按钮退出应用程序,然后关闭飞行模式.
  4. 通过点击图标重新启动NavigationBanner,然后出现错误.

这对我的应用程序来说是一个问题,因为我想在没有连接的情况下隐藏iAd,然后在连接恢复后重新显示它.如果应用收到限制错误,那么在收到其他广告之前会有很长时间的延迟.

如何避免节流错误?我认为bannerView需要被删除然后重新添加,但无法弄清楚如何正确地执行此操作.

最后要注意的是,当前的iAdSuite使用ARC而我的应用程序却没有.即便如此,我的app和iAdSuite也会出现错误.

小智 1

Try detecting the network status with the "Reachability" project code by Apple. There is an ARC compatible version on Github. (https://github.com/tonymillion/Reachability) Once you have Reachability.h imported in your header file, you can try the code below. Reachability will detect if any sort of connection is available and if not, then the iAd will be moved off screen. Hope this helps!

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

    NetworkStatus status = [reachability currentReachabilityStatus];

    if(status == NotReachable)
    {
        // No internet connection. We need to move the iAd off screen.
        NSLog(@"No network connection. iAd will hide.");
        banner.frame = CGRectOffset(banner.frame, 320, 0);
    }
    if(status == ReachableViaWifi)
    {
        banner.frame = CGRectOffset(banner.frame, your position here);
    }
    if(status == ReachableViaWWAN)
    {
        banner.frame = CGRectOffset(banner.frame, your position here);
    }
}
Run Code Online (Sandbox Code Playgroud)