1

我正在尝试在我正在开发的应用程序上测试 iAd。我已将设置中的填充率设置为 100%,刷新时间为 15 秒,但大部分时间我没有收到广告

我是否错过了为获得 100% 的填充率而做的事情?

我得到的错误是

横幅未加载 - 错误:错误域 = ADErrorDomain 代码 = 0“操作无法完成。未知错误” UserInfo = 0x1c5ec590 {ADInternalErrorCode = 7,ADInternalErrorDomain = ADErrorDomain,NSLocalizedFailureReason = 未知错误} 2013-09-17 14:09 :13.534 横幅未加载 - 错误:错误域 = ADErrorDomain 代码 = 2“操作无法完成。加载节流” UserInfo = 0x1d875bc0 {ADInternalErrorCode = 2,ADInternalErrorDomain = ADErrorDomain,NSLocalizedFailureReason =加载节流}

我偶尔也吃过这个

错误:错误域 = ADErrorDomain 代码 = 3“操作无法完成。广告库存不可用” UserInfo = 0x1e02da00 {ADInternalErrorCode = 3,ADInternalErrorDomain = ADErrorDomain,NSLocalizedFailureReason =广告库存不可用}

广告是使用单例类实现的。它们出现在第一个视图控制器上,但没有出现在任何其他视图控制器上(它们给出上述错误)

单例.h

#import <Foundation/Foundation.h>
#import <iAd/iAd.h>

@interface mt_iAdSinglton : NSObject <ADBannerViewDelegate>{
    ADBannerView *adView;
    BOOL bannerIsVisible;
}

@property (nonatomic, strong) ADBannerView *adView;

+(mt_iAdSinglton *)sharedAd;

-(void) attachAdToView:(UIView *)view;

@end

.m

#import "mt_iAdSinglton.h"

static mt_iAdSinglton *sharedAd = nil;

@implementation mt_iAdSinglton

@synthesize adView;

-(id)init{
    if (self) {
        if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
            adView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
        } else {
            adView = [[ADBannerView alloc] init];
        }
        CGRect screenBounds = [[UIScreen mainScreen] bounds];
        adView.frame = CGRectOffset(adView.frame, 0, screenBounds.size.height-50);
        adView.delegate = self;
    }
    return self;
}

- (BOOL)allowActionToRun
{
    return TRUE;
}

-(void) attachAdToView:(UIView *)view {
    if (bannerIsVisible) {
        [view addSubview:self.adView];
    }
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    [self.adView setHidden:NO];
    bannerIsVisible = YES;
    NSLog(@"Banner Loaded");
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    [self.adView setHidden:YES];
    bannerIsVisible = NO;
    NSLog(@"Banner Not Loaded - Error: %@", error);
}

+(mt_iAdSinglton *)sharedAd
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedAd = [[self alloc] init];
    });
    return sharedAd;
}

@end

然后在视图控制器中实现 .h @property ADBannerView *adView;

.m

- (void)viewDidLoad

{
    [super viewDidLoad];
     self.adView = [[mt_iAdSinglton sharedAd] adView];
}

- (void)viewDidAppear:(BOOL)animated {
    self.adView.frame = CGRectOffset(self.adView.frame, 0, -96.0f);
    [self.navigationController.view addSubview:self.adView];
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated{
    self.adView.frame = CGRectOffset(self.adView.frame, 0, 96.0f);
    [self.adView removeFromSuperview];
}
4

0 回答 0