0

。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];该应用程序在收到广告或不收到广告时都会抛出。但我似乎无法弄清楚......有人有什么想法吗?

4

1 回答 1

1

问题是你试图在一个 nil 对象上设置委托......在你分配它之前。正确的操作顺序是

bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
[bannerView_ setDelegate:self];
于 2013-06-05T19:26:20.303 回答