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.
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.