12

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:

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

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

To replicate the problem in iAdSuite do the following:

  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.

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.

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.

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.

vzm
  • 2,440
  • 6
  • 28
  • 47
user955853
  • 399
  • 2
  • 14
  • Don't know about the throttling error but why do you write there will be a long delay before receiving another ad ? It should be ok at the next iAd cycle so 3 minutes, no ? – gregory Nov 14 '11 at 21:25
  • @gregory After receiving the error, if an Ad is currently loaded it seems to "break" (the white border disappears and it can no longer be tapped), and if no Ad has been loaded yet, one never loads after the error is received. After quitting the app and re-launching again, the problem seems to resolve itself, but it seems like there is something not quite right with the code that Apple is providing for this to happen. – user955853 Nov 15 '11 at 07:32
  • This is confusing, I followed your steps exactly with the iAdSuite and this is the message I get at step 2 : Could not download configuration data Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline.". Note this is not an iAd error, but a NSURL eroor. At step 4 the ad appears. A far fetch but it sounds to me your iad framework could be reinstalled. – gregory Nov 15 '11 at 08:33
  • Did you add the NSLog statement to log any errors? I tried reinstalling Xcode 4.2 and I still get this error. I also tried this on two iPhones (4S and 3GS) and the same problem. Interestingly, on the 3GS, the NSURL error that you mention comes as well, but the NSURL error does not show on the 4S. – user955853 Nov 16 '11 at 04:55
  • Yes I followed exactly your steps, on an iPhone 4. No further idea I'm afraid. – gregory Nov 16 '11 at 07:16
  • 1
    @user955853 If you see a "broken" banner, try to remove it from the view hierarchy. e.g. call `[_bannerview removeFromSuperview];` when you receive an error. – t_motooka Apr 14 '12 at 01:40
  • 6
    Update: For anyone that is having the same issue, I was never able to resolve the problem and so I finally submitted a bug report to Apple. I received a response that this is now fixed in iOS 6, which I have checked and confirmed. Previous version of iOS will still have this issue. I hope this help someone else that may come across the same issue. – user955853 Oct 03 '12 at 05:26

2 Answers2

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);
    }
}
Kfeavel
  • 43
  • 1
  • 10
1
/*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

#import "AppDelegate.h"

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

//viewcontroller2

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