2015-02-24 95 views
1

我的應用程序在App Store上,它不顯示任何廣告。因此,聯繫Apple和接收無解後,我在控制檯中看到這個錯誤,同時運行在模擬器上我的應用程序:ADBannerView錯誤(沒有委託或委託沒有實現didFailToReceiveAdWithError :)

[AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=1 "Service session terminated." UserInfo=0x7f18e160 {ADInternalErrorCode=1002, NSLocalizedDescription=Service session terminated.} 

這就是爲什麼我的應用程序不顯示任何廣告,只是原因顯示白色ADBannerView是哪裏?

+2

好吧,考慮到錯誤,它可能是一個很好的開始。您也可能在嘗試加載廣告時發生錯誤,並引發此異常,以通知您沒有任何內容會攔截該錯誤。 – 2015-02-24 19:57:48

+0

該錯誤不是廣告未顯示的原因。我不知道原因是什麼,這可能僅僅是因爲目前沒有適用於您的應用的廣告(填充率並非總是100%)。這就是爲什麼你需要實現didFailToReceiveAdWithError來處理這種情況。例如,您可以隱藏橫幅,以便用戶看不到空的白色矩形。 – almas 2015-02-24 23:09:08

回答

0

聽起來像你沒有包括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; 
} 
+0

謝謝,在我的應用程序今天沒有廣告出現一週後,他們剛剛出現,這意味着代碼可以正常使用 – 2015-02-25 05:43:00