聽起來像你沒有包括ADBannerView
的委託方法。我已經評論過您的代碼中可能缺少的部分。
#import <iAd/iAd.h>
@interface ViewController() <ADBannerViewDelegate> // Have you included this?
@end
@implementation ViewController {
// Your iAd Banner
ADBannerView *iAdView;
}
-(void)viewDidLoad {
[super viewDidLoad];
// Setup iAd view
iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
iAdView.delegate = self; // And have you done this?
[iAdView setFrame:CGRectMake(0, 0, iAdView.bounds.size.width, iAdView.bounds.size.height)];
iAdView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height - (iAdView.bounds.size.height/2));
[self.view addSubview:iAdView];
iAdView.alpha = 0.0;
}
// And have you included these delegate methods to handle when an ad is received or not?
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"iAd received ad");
// display ad
iAdView.alpha = 1.0;
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"iAd failed");
// Hide ad
iAdView.alpha = 0.0;
}
好吧,考慮到錯誤,它可能是一個很好的開始。您也可能在嘗試加載廣告時發生錯誤,並引發此異常,以通知您沒有任何內容會攔截該錯誤。 – 2015-02-24 19:57:48
該錯誤不是廣告未顯示的原因。我不知道原因是什麼,這可能僅僅是因爲目前沒有適用於您的應用的廣告(填充率並非總是100%)。這就是爲什麼你需要實現didFailToReceiveAdWithError來處理這種情況。例如,您可以隱藏橫幅,以便用戶看不到空的白色矩形。 – almas 2015-02-24 23:09:08