简体   繁体   中英

iAd banner shows test ad on simulator but not on device

I am trying to put an iAd banner on my iPhone app. Here is where I declare the banner ad:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1];

    [banner setAlpha:1];

    [UIView commitAnimations];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1];

    [banner setAlpha:0];

    [UIView commitAnimations];
}

When I test on the simulator, the test ad shows up straight away. When I test on my device, nothing shows up.

I have recently registered with Apple's iAd system, but when I try look look at the iAd section of iTunes Connect, it tells me that the iAd network is currently unavailable. Is this why the test ad won't show up on my device? If so, why is it still showing up on the simulator?

This is because before ads can be displayed, your device has to contact the iAD servers, search threw the tens (if not hundreds) of thousands of ads, decide which one is the best fit for your app, send the information of the ad to your ios device, and then send a confirmation back to iAD servers, and none of this can be done without good internet connection.

Yet, on the ios simulator , none of the above has to happen, and the simulator simply displays the test ad no matter what.

I have two apps on the app store that use the exact same code as you do, and do display ads, with the delay that you described. So, there are no errors with your code, and the delay for ads to be displayed is completely normal.

So, as you can see, lots of things have to happen before an iAD can be displayed on an actual ios device, and even then, you have to have a strong internet connection

I hope this can be helpful to new users, this works for me:

In ViewController.h

  @interface ViewController : UIViewController <ADBannerViewDelegate> {    
  }
  @property (nonatomic, strong) ADBannerView *banner;
  @end

And in ViewController

- (void)viewDidLoad{
  [super viewDidLoad];
  //self.canDisplayBannerAds = YES; This give me a error    
  self.banner = [[ADBannerView alloc] initWithFrame:CGRectZero];
  self.banner.delegate = self;
  [self.banner sizeToFit];
  self.banner.hidden = true;
}

And last thing:

Implement two methods:

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (banner.isBannerLoaded) {
    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    // Assumes the banner view is placed at the bottom of the screen.
    banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
    [UIView commitAnimations];
 }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
 NSLog(@"Showing iAd");
 self.banner.hidden = false;
 ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,    self.view.frame.size.height - 50, 320, 50)];
  //adView.delegate = self;
 [self.view addSubview:adView];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM