2013-02-17 68 views
0

.HAdMob Mediation SDK不投放失敗的廣告?

#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

問題是,您正試圖在分配它之前將委託設置在零對象上。正確的操作順序是

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