2

I'm trying to add AdMob to my app. My app is build with : UITabBarController with 1. UIViewController; 2. UITableViewController; 3. UIViewController; 4. UIViewController.

I'm actually tring to add a Banner Ad from Admob in the 3. UIViewController.

I used that code:

@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())

And it not works : ad isn't displayed. So I used that function:

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

And I got this output: adView:didFailToReceiveAdWithError: Request Error: No ad to show.

I really think it's due to amobBan.rootViewController = self since Ad is showed when I set the 3. UIViewController as the Initial ViewController into the Storyboard.

I need answers in Swift, please.

6
  • You don´t allways get and ad back, if you are testing you should use adUnitID for testing. here is a link to a similar answer stackoverflow.com/a/32877187/4905076
    – Lucho
    Commented Apr 23, 2016 at 15:18
  • adUnitID change nothing, and on a default project or when I change the Initial ViewController the ad is shown...
    – Julian B
    Commented Apr 27, 2016 at 1:14
  • 1
    you should call amob.loadRequest(GADRequest()) when the controller's view is visible, aka when you select its tab. If you call it on viewDidLoad of a viewController that is not visible it won't work.
    – Lucho
    Commented Apr 27, 2016 at 15:45
  • It was actually in viewDidLoad, so I put it in viewDidAppear but same error
    – Julian B
    Commented Apr 27, 2016 at 16:21
  • but it gets executed when is visible? try attaching it to a button tap or similar.
    – Lucho
    Commented Apr 27, 2016 at 16:24

4 Answers 4

3

Add your test devices - real devices and the simulator. You may find your test device string in Xcode output pane.

let request: GADRequest = GADRequest()
    request.testDevices = [ "661359a1bfeb6e588caf9c8133904d10", "96a6d0a80ffaa7094ad91b6648b6b50f", kGADSimulatorID ]
    bannerView.load(request)
2

Late answer but this may helps to other.

If you are facing issue like "No ad to show" in cases if you are using google banner ads(admob) then that issue solved by making view width 320 fixed.I solved my issue by making ad width 320 and height 50.

Hope this will helpful for others.

1
  • 1
    Great. :) I get to know the issue at my end now. Thanks for providing this information.
    – user9685203
    Commented Sep 4, 2018 at 6:58
0

Use a test ad unit id, or add a test device

-2

Google's documentation is pretty straight forward so maybe you should take a look into it.

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

At first glance I have a question:

Are you configuring AdMob in your 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
  }

Some tips, like Payal Umraliya said, size is a pretty big deal in admob, so make sure adview has the same size of the ad you are requesting.

1
  • This method is deprecated. You should use new method. ... GADMobileAds.sharedInstance().start(completionHandler: nil)
    – Mehul
    Commented Mar 17, 2020 at 12:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.