AdMob Mediation SDK不会丢失失败的广告?

时间:2013-02-17 05:49:28

标签: iphone ios objective-c admob iad

·H

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

#import "GADBannerView.h"

@interface MasterTableViewController : UITableViewController <GADBannerViewDelegate >{

GADBannerView *bannerView_;

}

@end

的.m

#import "MasterTableViewController.h"

@interface MasterTableViewController ()

@end

@implementation MasterTableViewController


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
{
    NSLog(@"Ad failed");
    bannerView_.hidden = YES;
}

- (void)adViewDidRecieveAd:(GADBannerView *)view
{
    NSLog(@"Ad recieved");
    bannerView_.hidden = NO;
}

- (void) repeatAdRequest
{
    [bannerView_ loadRequest:[GADRequest request]];
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    [bannerView_ setDelegate:self];

    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    bannerView_.adUnitID = @"ID_HERE";

    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];

    [bannerView_ loadRequest:[GADRequest request]];

}

问题是,当我在手机上完全禁用网络时,没有广告显示(显然),但它也不会抛出didFailToReceiveAdWithError。然后,我在手机上重新启用我的网络,没有任何反应。如果广告失败,广告不会刷新?我已经查看过许多其他帖子,声称可以使用[bannerView_ setDelegate:self];修复该应用,但是当应用收到广告时,该应用会抛出。但我似乎无法弄明白......有没有人有任何想法?

1 个答案:

答案 0 :(得分:1)

问题是您在分配之前尝试在nil对象上设置委托。正确的操作顺序是

bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
[bannerView_ setDelegate:self];