2011-05-09 17 views
4

我試圖將AdMob添加到我的應用程序。iPhone - AdMob沒有出現。使用示例代碼

我跟着從例如從這裏的說明:與我創建了一個方法,我從viewDidLoad中

問題調用它的細微差別http://code.google.com/mobile/ads/docs/ios/fundamentals.html

是毫無顯現,不甚至是一個空框架。我也嘗試刪除除界面生成器的主視圖以外的所有內容,以確保它不在後面,但沒有任何內容出現。

我能做什麼錯?

這裏是我的方法的代碼:

- (void)showBanner { 

    // Create a view of the standard size at the bottom of the screen. 
    bannerView_ = [[GADBannerView alloc] 
        initWithFrame:CGRectMake(0.0, 
              self.view.frame.size.height - 
              GAD_SIZE_320x50.height, 
              GAD_SIZE_320x50.width, 
              GAD_SIZE_320x50.height)]; 

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID. 
    bannerView_.adUnitID = @"heresthestringofmyadmobid"; 

    // Let the runtime know which UIViewController to restore after taking 
    // the user wherever the ad goes and add it to the view hierarchy. 
    bannerView_.rootViewController = self; 
    [self.view addSubview:bannerView_]; 
    [self.view bringSubviewToFront:bannerView_]; 

    // Initiate a generic request to load it with an ad. 
    GADRequest *request = [GADRequest request]; 

    request.testDevices = [NSArray arrayWithObjects: 
          GAD_SIMULATOR_ID,        // Simulator 
          @"heresthestringofmyphone", // Test iPhone 3Gs 4.3.1 
          nil]; 

    [bannerView_ loadRequest:request]; 


} 

我也試過harcoding的CGFrame 0,0,320,50,使其出現在頂部,但什麼都沒有發生任何

回答

4

Chompas,

由於填充率低或其他問題,您無法獲得廣告。要檢查這是否是問題,請嘗試啓用testMode,以便始終獲取廣告。

你可以做到這一點是這樣的:

GADRequest *request = [[GADRequest alloc] init]; 
request.testing = YES; 
[bannerView_ loadRequest:request]; 

-David

+1

我試過也沒有運氣。我也嘗試過使用testdevices數組。 也許可以是admob頁面中的設置?我剛剛下載了示例代碼項目並運行它。沒有運氣要麼=( – Chompas 2011-05-09 02:49:23

+0

爲我工作.......感謝兄弟... :) – 2013-06-18 04:46:56

0

我想你錯過設置委託處理事件,如收到的廣告,廣告失敗了,等我做了同樣的錯誤。 [adView setDelegate:]]

+0

我沒有錯過任何東西。開始工作後的第二天神奇地(?¿?¿?¿)感謝您的回答 – Chompas 2011-06-29 19:27:52

3

.testing現已棄用。如果你想在真實設備測試廣告支持,而不是僅僅在模擬器中,YOUR_DEVICE_IDENTIFIER應該由你的設備標識符,你可以找到當您的設備下連接更換

#ifdef DEBUG 
    GADRequest *request = [GADRequest request]; 
    request.testDevices = [NSArray arrayWithObjects: 
          GAD_SIMULATOR_ID, 
          @"YOUR_DEVICE_IDENTIFIER", 
          nil]; 
    [bannerView_ loadRequest:request]; 
#else 
    [bannerView_ loadRequest:[GADRequest request]]; 
#endif 

:您可以使用它代替xCode菜單>窗口>管理器>設備。這是一個很長的十六進制數字。

+0

我唯一的問題是:爲什麼谷歌不包括這個代碼在那裏的例子。本來會救了我很多亂七八糟的東西。 – 2014-02-28 06:11:42