iAds重新启动应用程序后从背景(也发生在iAdSuite) [英] iAds Loading Throttled After Re-Launching App From Background (Also Happens In iAdSuite)

查看:97
本文介绍了iAds重新启动应用程序后从背景(也发生在iAdSuite)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to implement the NavigationBanner iAdSuite example into my project so that a I can share a single AdBannerView instance across multiple view controllers, but I keep getting the following error:

错误域= ADErrorDomain代码= 2无法完成操作

Error Domain=ADErrorDomain Code=2 "The operation couldn’t be completed. Loading throttled

我已将相关代码从当前iAdSuite复制到我自己的应用程序中,并收到此错误事实上,错误是可重复的在苹果自己的iAdSuite示例NavigationBanner(这是我想要实现的示例)。错误可以通过添加:

I have copied the relevant code exactly from the current iAdSuite into my own app and am getting this error. In fact, this error is repeatable in Apple's own iAdSuite example for NavigationBanner (which is the example I am trying to implement). The error can be seen by adding:

NSLog (@"%@",error);



to:

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error

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

To replicate the problem in iAdSuite do the following:


  1. 将您的设备飞行模式设为开

  2. 从Xcode启动iAdSuite NavigationBanner。这会立即产生「ADErrorDomain error 1」的错误讯息。

  3. 按下装置上的[首页]按钮退出应用程式,然后关闭飞航模式。

  4. 点击图标重新启动NavigationBanner,并显示错误。

  1. Turn your device Airplane mode to On
  2. Launch iAdSuite NavigationBanner from Xcode. This generates an error right away "ADErrorDomain error 1".
  3. Exit the app by pressing the Home button on your device, then turn Airplane mode Off.
  4. Re-launch NavigationBanner by tapping the icon, and the error appears.

这是我的应用程序的问题,因为我想如果没有连接,则隐藏iAd,然后在连接恢复后重新显示。如果应用程序收到限制错误,那么在接收另一个广告之前会有很长的延迟。

This is a problem for my application because I want to hide the iAd if there is no connectivity, and then have it re-appear once connectivity resumes. If the app receives the throttling error, then there will be a long delay before it can receive another ad.

如何避免限制错误?我认为bannerView需要删除然后重新添加,但无法弄清楚如何正确地这样做。

How can the throttling error be avoided? I was thinking that the bannerView needs to be removed and then re-added, but could not figure out how to do this correctly.

最后要注意的是,当前iAdSuite使用ARC,而我的应用程序不使用ARC。即使这样,我的应用程序和iAdSuite都会发生错误。

One last thing to note is that the current iAdSuite uses ARC while my application does not. Even so, the error occurs with both my app and iAdSuite.

推荐答案

/*Implement the iAd in app delegate and use the applicationDidBecomeActive method.Here I use #import "Reachability.h" class downloaded from Github Here is the code.*/




//  AppDelegate.h




 @interface AppDelegate : UIResponder <UIApplicationDelegate,ADBannerViewDelegate>
    {

      BOOL iAdLauchFlag;
      ADBannerView *bannerView;
      UILabel  *notifier ;
      UIView *iAdview;
    }

//  AppDelegate.m




  #import "AppDelegate.h"

  #import "Reachability.h"



    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

    {

      LauchFlag=NO;

      notifier=[[UILabel alloc]init];

      notifier=[[UILabel alloc]initWithFrame:CGRectMake(0.0f, 40.0f, bounds.size.height, 30)];

       iAdview =[[UIView      alloc]initWithFrame:CGRectMake(0.0f,bounds.size.width,bounds.size.height, 30)]; 

    }

    -(void) applicationDidBecomeActive: (UIApplication *) application 
    {

        NSLog(@"applicationDidBecomeActive");

     if ( [self connectedToNetwork] )

      {

          if(!LauchFlag)
            {
              CGRect bounds=[[UIScreen mainScreen] bounds];

              NSLog(@"allocated banner view");

             bannerView = [[ADBannerView alloc]
                          initWithFrame:CGRectMake(0.0f, 30.0f, bounds.size.height, 30)];


             [notifier setText:@"  Connecting to iAd service......."];
             [iAdview addSubview:notifier];
            }
            bannerView.delegate = self;


        }
        else
        {
            if(LauchFlag)
            {
                [bannerView removeFromSuperview];
                [bannerView release];
                 LauchFlag=NO;
            }
            [notifier setText:@" iAd failed to launch due to internet connection problem "];
            [iAdview addSubview:notifier];
        }

    }

    -(BOOL)bannerViewActionShouldBegin:
    (ADBannerView *)banner
                   willLeaveApplication:(BOOL)willLeave{


     return YES;

    }

    - (void)bannerViewActionDidFinish:(ADBannerView *)banner
    {
    }

    -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    {

        NSLog(@"bannerView:(ADBannerView *)banner didFailToReceiveAdWithError");


        if ([self connectedToNetwork]) {

            [notifier setText:@" Launching iAd ............"];


            NSLog(@"Reachable");
        }
        else {

            [notifier setText:@"error: iAd failed to launch due internet connection problem "];


            NSLog(@"Not Reachable");
        }


    }

    -(void)bannerViewDidLoadAd:(ADBannerView *)banner
    {

        NSLog(@"bannerViewDidLoadAd");
        [notifier removeFromSuperview];
        [iAdview  addSubview:bannerView];
         LauchFlag=YES;

    }
- (BOOL) connectedToNetwork
{
    Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    BOOL internet;
    if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN)) {
        internet = NO;
    } else {
        internet = YES;
    }
    return internet;
}

// viewcontroller1

// viewcontroller1

#import "AppDelegate.h"

 - (void)viewDidLoad
{
     AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
      [[self view] addSubview:appdelegate.iAdview];
}

// viewcontroller2

//viewcontroller2

#import "AppDelegate.h"
 - (void)viewDidLoad
{
    AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
     [[self view] addSubview:appdelegate.iAdview];
}

这篇关于iAds重新启动应用程序后从背景(也发生在iAdSuite)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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