2013-10-10 212 views
3

我想補充ADMOB到我的Xcode項目,但是當在iPhone和模擬器測試它,我收到此錯誤:AdMob的Ios的錯誤:無法獲得廣告與錯誤:請求錯誤:沒有廣告顯示

AdMob Ios Error: Failed to receive ad with error: Request Error: No ad to show.

我的代碼Banner.h:

#import <UIKit/UIKit.h> 
#import "GADBannerViewDelegate.h" 

@class GADBannerView, GADRequest; 

@interface BannerExampleViewController : UIViewController 
    <GADBannerViewDelegate> { 
    GADBannerView *adBanner_; 
} 

@property (nonatomic, retain) GADBannerView *adBanner; 

- (GADRequest *)createRequest; 

@end 

Banner.m

#import "BannerExampleViewController.h" 
#import "GADBannerView.h" 
#import "GADRequest.h" 
#import "SampleConstants.h" 

@implementation BannerExampleViewController 

@synthesize adBanner = adBanner_; 

#pragma mark init/dealloc 

// Implement viewDidLoad to do additional setup after loading the view, 
// typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Initialize the banner at the bottom of the screen. 
    CGPoint origin = CGPointMake(0.0, 
           self.view.frame.size.height - 
           CGSizeFromGADAdSize(kGADAdSizeBanner).height); 

    // Use predefined GADAdSize constants to define the GADBannerView. 
    self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner 
                origin:origin] 
        autorelease]; 

    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID 
    // before compiling. 
    self.adBanner.adUnitID = kSampleAdUnitID; 
    self.adBanner.delegate = self; 
    [self.adBanner setRootViewController:self]; 
    [self.view addSubview:self.adBanner]; 
    self.adBanner.center = 
     CGPointMake(self.view.center.x, self.adBanner.center.y); 
    [self.adBanner loadRequest:[self createRequest]]; 
} 

- (void)dealloc { 
    adBanner_.delegate = nil; 
    [adBanner_ release]; 
    [super dealloc]; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

#pragma mark GADRequest generation 

// Here we're creating a simple GADRequest and whitelisting the application 
// for test ads. You should request test ads during development to avoid 
// generating invalid impressions and clicks. 
- (GADRequest *)createRequest { 
    GADRequest *request = [GADRequest request]; 

    // Make the request for a test ad. Put in an identifier for the simulator as 
    // well as any devices you want to receive test ads. 
    request.testDevices = 
     [NSArray arrayWithObjects:@"6a47e320f03fe2ab9854afe2e5708321", nil]; 
    return request; 
} 

#pragma mark GADBannerViewDelegate impl 

// We've received an ad successfully. 
- (void)adViewDidReceiveAd:(GADBannerView *)adView { 
    NSLog(@"Received ad successfully"); 
} 

- (void)adView:(GADBannerView *)view 
    didFailToReceiveAdWithError:(GADRequestError *)error { 
    NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]); 
} 

@end 
+0

一切看起來不錯,請確保您的AdMob的「kSampleAdUnitID」鍵是完美的。 –

+1

@ D-eptdeveloper是的..我敢肯定 –

+1

同樣的錯誤:無法接收帶有錯誤的廣告:請求錯誤:無廣告顯示。 –

回答

0

這是因爲服務器尚未更新。 您應該等待15分鐘,然後重試,它會正常工作。

PS:記住AdMob的

此代碼正常工作與你的App ID替換kSampleAdUnitID當我用我的ID

+0

你怎麼知道我們應該等15分鐘? – KarenAnne

+0

服務器不立即響應,這就是爲什麼你應該等待。如果您添加應用程序並讓您的遊戲立即運行,它將無法工作,因爲它不在系統中。 – Huygamer

+0

呃你是說,等15分鐘後,你已經添加?廣告之間的時間間隔如何? – KarenAnne

6

還有一點需要指出的測試 - 如果您的橫幅廣告空間寬度/高度設置爲0,您將收到完全相同的錯誤。我目前正在嘗試解決此問題,因爲我只想在廣告成功加載時在屏幕上爲廣告視圖設置動畫效果。

+0

你管理過嗎? – Yitzchak

+0

明白了,Admob不喜歡我們在橫幅視圖中使用隱藏。但是,當我們從超級視圖中移除並添加時,它會很喜歡。動畫不太優雅。但沒有錯誤! – Yitzchak

+0

嗨,你解決了這個問題..高度問題 –

相關問題