Julian B
Julian B

Reputation: 103

Swift & Admob : No ad to show

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.

Upvotes: 2

Views: 6750

Answers (4)

tonisives
tonisives

Reputation: 2528

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

Upvotes: 0

Panayot
Panayot

Reputation: 554

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)

Upvotes: 3

Pedro Carrasco
Pedro Carrasco

Reputation: 158

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.

Upvotes: -2

iDeveloper
iDeveloper

Reputation: 627

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.

Upvotes: 2

Related Questions