2016-04-23 97 views
0

我正在嘗試將AdMob添加到我的應用中。 我的應用程序構建於: UITabBarController with 1. UIViewController; 2. UITableViewController; 3. UIViewController; 4. UIViewController。Swift&Admob:無廣告展示

我實際上是在3. UIViewController中從Admob添加橫幅廣告。

我使用的代碼:

@IBOutlet weak var amobBan: GADBannerView! 
[•••] 
amobBan.delegate = self 
amobBan.adUnitID = "ca-app-pub-xxxxxxx" // I used mine in other apps : it works. 
amobBan.rootViewController = self // NB: I also tried with tabBarController istead "self" 
amobBan.loadRequest(GADRequest()) 

而且它不工作:不顯示廣告。 所以我用這個函數:

func adView(bannerView: GADBannerView!, 
      didFailToReceiveAdWithError error: GADRequestError!) { 
    print("adView:didFailToReceiveAdWithError: \(error.localizedDescription)") 
} 

而且我得到了這樣的輸出: 的AdView:didFailToReceiveAdWithError:請求錯誤:沒有廣告顯示。

我真的認爲這是由於amobBan.rootViewController =自我,因爲廣告當我設置3的UIViewController作爲初始的ViewController到故事板顯示。

我需要Swift中的答案。

+0

如果您正在測試您不應該得到和回廣告,應該使用adUnitID進行測試。這裏是一個類似的答案鏈接http://stackoverflow.com/a/32877187/4905076 – Lucho

+0

adUnitID沒有改變,並在一個默認的項目或當我更改初始ViewController的廣告顯示... –

+1

你應該打電話' amob.loadRequest(GADRequest())'當控制器的視圖可見時,也就是當您選擇其選項卡時。如果你在viewController的viewDidLoad上調用它是不可見的,它將無法工作。 – Lucho

回答

1

遲到的答案,但這可能有助於其他。

如果您在使用谷歌旗幟廣告(admob)時遇到了「無廣告顯示」的問題,那麼通過將視圖寬度320固定來解決該問題。我通過將廣告寬度320和高度解決了我的問題50.

希望這會對其他人有所幫助。

0

谷歌的文檔非常直截了當,所以也許你應該看看它。

https://developers.google.com/admob/ios/banner

乍一看我有一個問題:

你配置的AdMob在你的AppDelegate didFinishLaunching?

func application(_ application: UIApplication, 
     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Initialize the Google Mobile Ads SDK. 
    // Sample AdMob app ID: ca-app-pub-3940256099942544~1458002511 
    GADMobileAds.configure(withApplicationID: "YOUR_ADMOB_APP_ID") 

    return true 
    } 

一些技巧,比如PAYAL Umraliya說,規模是AdMob一個相當大的交易,所以一定要確保AD瀏覽有您所請求的廣告的尺寸相同。