简体   繁体   English

iAd横幅无法在iOS 9上运行

[英]iAd banner not working on iOS 9

I'm getting didFailToReceiveAdWithError message in the console while running on the simulator and device. 我在模拟器和设备上运行时在控制台中收到didFailToReceiveAdWithError消息。

iAd banners are displayed successfully when running on iOS 8. When running on iOS 9, iAd banners fail to receive an ad. 在iOS 8上运行时,iAd横幅会成功显示。在iOS 9上运行时,iAd横幅无法接收广告。

.h 。H

#import <iAd/iAd.h>
@interface ViewController : UIViewController <ADBannerViewDelegate>

@property (retain, nonatomic) IBOutlet ADBannerView *adBanner;

.m .M

-(void)viewDidLoad {
    self.adBanner = [[ADBannerView alloc]initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height-100, [UIScreen mainScreen].bounds.size.width, 50)];
    self.adBanner.delegate=self;
    [self.adBanner setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:self.adBanner];
}   

-(void)bannerViewWillLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewWillLoadAd");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    // Show the ad banner.
    NSLog(@"bannerViewDidLoadAd");

    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 1.0;
    }];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"didFailToReceiveAdWithError");

    // Hide the ad banner.
    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 0.0;
    }];
}    

-(void)bannerViewActionDidFinish:(ADBannerView *)banner {
    NSLog(@"Ad did finish");
}

When running on iOS 9, the console prints didFailToReceiveAdWithError every time. 在iOS 9上运行时,控制台每次都会打印didFailToReceiveAdWithError

I'm unable to recreate your issue. 我无法重新创建您的问题。 The iAd network may have been down for your country when testing this, you may be in a country that iAd does not support, or it may be that you've set your iAd Testing Fill Rate to 0% on your development device/simulator. 在测试时,您的国家/地区的iAd网络可能已关闭,您可能位于iAd不支持的国家/地区,或者您可能在开发设备/模拟器上将iAd测试填充率设置为0%。 Go to Settings>Developer>Fill Rate> and check that Fill Rate is set to 100% on your development device/simulator. 转到设置>开发人员>填充率>,然后检查开发设备/模拟器上的填充率是否设置为100%。

I'd suggest printing the error you're receiving in didFailToReceiveAdWithError so you can find out why the ADBannerView is failing. 我建议打印你在didFailToReceiveAdWithError收到的error ,这样你就可以找出ADBannerView失败的原因。

-(void)viewDidLoad {
    // The ADBannerView will size itself based on the device it is being displayed on
    // Only setting the position is sufficient
    self.adBanner = [[ADBannerView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-100, 0, 0)];
    self.adBanner.delegate=self;
    // Removed setBackgroundColor
    // Set alpha to 0.0 initially
    self.adBanner.alpha = 0.0;
    [self.view addSubview:self.adBanner];
}

-(void)bannerViewWillLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewWillLoadAd");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewDidLoadAd");
    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 1.0;
    }];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    // Changed NSLog to print the error that is received
    NSLog(@"didFailToReceiveAdWithError: %@", error);
    [UIView animateWithDuration:0.5 animations:^{
        self.adBanner.alpha = 0.0;
    }];
}

-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    NSLog(@"bannerViewActionDidFinish");
}

If you're still having this issue you should contact iAd directly and update your question based on their response, or post an answer if they're able to solve it for you. 如果您仍然遇到此问题,请直接与iAd联系并根据他们的回复更新您的问题,或者如果他们能够为您解决问题,请回复。

Try adding app transport security in your project's plist file. 尝试在项目的plist文件中添加app transport security。 在此输入图像描述

I found this here : 我在这里找到了这个:

Checking my storyboard I noticed, that a height constraint for 32 was set for the ADBannerView - the 32 was not a valid height in that orientation. 检查我的故事板我注意到,为ADBannerView设置了32的高度约束 - 32在该方向上不是有效高度。 Removing that height constraint removed the error "Ad inventory unavailable" and it worked beautifully from then on. 删除该高度限制删除了错误“广告库存不可用”,从那时起它就能很好地工作。

Check if that works for you. 检查这是否适合您。

Also check with the iAD Changelog to see if there's anything you might need to worry about. 还要查看iAD Changelog ,看看是否有任何您可能需要担心的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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