我正在尝试在我正在开发的应用上测试iAds。我已将设置中的填充率设置为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 =加载限制}
我偶尔也有这个
错误:错误Domain = ADErrorDomain Code = 3“操作无法执行 完成。广告资源不可用“UserInfo = 0x1e02da00 {ADInternalErrorCode = 3,ADInternalErrorDomain = ADErrorDomain, NSLocalizedFailureReason =广告资源不可用}
广告使用singlton类实现。它们出现在第一个视图控制器上,但不出现在任何其他视图控制器上(它们会出现上述错误)
singleton .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];
}