ios - iAd 横幅不适用于 iOS 9

标签 ios objective-c ios9 iad

在模拟器和设备上运行时,我在控制台中收到 didFailToReceiveAdWithError 消息。

iAd banners 在 iOS 8 上运行时显示成功。在 iOS 9 上运行时,iAd banners 接收不到广告。

.h

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

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

.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");
}

在iOS 9上运行时,控制台每次都会打印didFailToReceiveAdWithError

最佳答案

我无法重现您的问题。测试时 iAd 网络可能在您所在的国家/地区出现故障,您所在的国家/地区可能 iAd 不支持,或者您在开发设备/模拟器上将 iAd 测试填充率设置为 0%。转到设置>开发人员>填充率>并检查您的开发设备/模拟器上的填充率是否设置为 100%。

我建议打印 error你收到 didFailToReceiveAdWithError这样你就可以找出为什么 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");
}

如果您仍然遇到此问题,您应该 contact iAd直接并根据他们的回答更新您的问题,或者在他们能够为您解决的情况下发布答案。

关于ios - iAd 横幅不适用于 iOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34238980/

相关文章:

ios - 如何在 Swift 的表格 View 单元格中添加自定义 ImageView ?

ios - 使用适用于 iOS 的开源 SQLCipher 将应用上传到应用商店以供审核

objective-c - 如果 iAds 失败,如何集成 iAds 和 AdMob

iOS - AudioToolbox 内存泄漏

objective-c - gdb:在 NSManagedObject 子类上调用访问器方法?

iOS 9 在带有 EXC_BAD_ACCESS KERN_INVALID_ADDRESS 的 _prepareForCAFlush 中崩溃

google-places-api - 无法使用 Xcode 7/iOS9 使用 Google Maps API 在路径错误时加载优化模型

ios - 如何分辨什么代码正在调用方法?

ios - 有没有办法在 LinkedIn iOS 集成中访问 r_fullprofile 权限?

Apple 评论崩溃 - iOS