Why is my AdMob interstitial working fine in Xcode Simulator but not on my test devices?
You are attempting to present your interstitial before it has a chance to load. Your timer
fires func presentInterstitial
after one second. Change this to a larger number to give the interstitial time to load.
import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADInterstitialDelegate {
var admobInterstitial : GADInterstitial?
var timer : NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
admobInterstitial = createAndLoadInterstitial()
timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target:self, selector: Selector("presentInterstitial"), userInfo: nil, repeats: false)
}
func createAndLoadInterstitial()->GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "yourAdMobADUnitID")
interstitial.delegate = self
interstitial.loadRequest(GADRequest())
return interstitial
}
func presentInterstitial() {
if let isReady = admobInterstitial?.isReady {
admobInterstitial?.presentFromRootViewController(self)
}
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
println("interstitialDidFailToReceiveAdWithError:\(error.localizedDescription)")
admobInterstitial = createAndLoadInterstitial()
}
How to show a real Admob ad rather than the test ad?
Do this:
1-remove "request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
2- Create an Admob account on google's website, then create an app in your account,then, replace the default adUnitID given in the google's tutorial with the one in the created app.
3- Then, instead of test ad, you might get a full black screen ad. This one is because it takes a few hours before google starts to send real ads. Hope that helps.
Admob works for interstitial, but not for the banner
they use the same Ad unit ID
This is your problem. Each ad needs its own unique Ad unit ID. One Ad unit ID for the interstitial ad, and one Ad unit ID for the banner ad in your case. The reason the interstitial works and the banner does not is because you have the correct Ad unit ID set for your interstitial whereas your banner can not use an interstitial Ad unit ID.
- Go to AdMob.com
- Click Monetize
- Click "YourApplicationName"
- Click New Ad Unit
- Select Banner and follow the setup
- Implement the newly generated Ad unit ID for your banner in your application
Related Topics
iOS 10.3 - How to Change App Icon Programmatically
How to Convert Bytes to Half-Floats in Swift
Ios11 Uibarbuttonitem Not Working
Swift Parse - Local Datastore and Displaying Objects in a Tableview
Load Offline Cached JSON Using Afnetworking
Indexing into Array of Functions: Expression Resolves to an Unused L-Value
Making the Map Zoom to User Location and Annotation (Swift 2)
How to Make Custom Keyboard Only for My App in Swift
Video Thumbnail Taking 10-15 Secs to Display
Swift 3 Filter Array of Dictionaries by String Value of Key in Dictionary
How to Get All Events Out of a Calendar (Swift)
Tableview with Searchcontroller - Deinit Not Called
Ambiguous Use of Registerclass with Swift
Realmswift Cannot Cast Results<Someojbect> to Results<Object>
Viewing Os_Log Messages in Device Console
Uitapgesturerecognizer Called Immediately
Swift 4: Timer Crashing - Unrecognized Selector Sent to Instance