Admob Ads not displaying iOS - ios

I have a banner ad and an interstitial ad. They are appearing when I use the adUnitID's for testing purposes that AdMob gives you, but neither of them are showing when I use live ads. The banner just doesn't appear at all. When the interstitial ad appears, it is just completely black. The adUnitID's are correct. The ads on my other apps are currently appearing just fine. The problem occurs both when I use the iOS simulator and my device. Any ideas?
var interstitial: GADInterstitial!
func createAndLoadAd() -> GADInterstitial{
let ad = GADInterstitial(adUnitID: "ca-app-pub-7863284438864645/1835730011")
let request = GADRequest()
ad.loadRequest(request)
return ad
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
authenticateLocalPlayer()
self.bannerView.adUnitID = "ca-app-pub-7863284438864645/9358996816"
self.bannerView.rootViewController = self
let request: GADRequest = GADRequest()
self.bannerView.loadRequest(request)
self.interstitial = self.createAndLoadAd()
}
override func viewDidAppear(animated: Bool) {
_ = GADRequest()
//request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
showAd()
}
func showAd(){
if(self.interstitial.isReady){
print("ad ready")
self.interstitial.presentFromRootViewController(self)
}
else{
print("ad not ready")
self.interstitial = createAndLoadAd()
}
}

This is an aside, because my problem looked similar, but was not.
App ID is NOT the same as Ad Unit ID.
And, stupidly, they BOTH start with ca-app-pub- and a lot of numbers. I was using the App ID which I can guarantee 100% does NOT work.
Yes, I feel pretty silly, but the folks at Google should have made them dissimilar.

replace adUnitID with your own ad unit id in your Admob account.
make sure you setup payment method, otherwise the ads wont show up

They have both IDs that contains "~" telda and "/" slash

Related

How do I transition from test ads to real ads when I launch my app?

I am using a test ad and loading it through a test device. I am about to put my app on the app store so that test device won't exist. I know I need to change my ad key to the real one, but how should I change the code so that it loads on the users device and not a test device?
func createInterstitialAd() -> GADInterstitial? {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
guard let interstitial = interstitial else {
return nil
}
let request = GADRequest()
request.testDevices = [kGADSimulatorID]
interstitial.load(request)
interstitial.delegate = self
return interstitial
}
Can’t you just edit the production app ID into your function before you deploy it? As stated in the Admob interstitial docs, “Just make sure you replace it with your own ad unit ID before publishing your app.”
https://developers.google.com/admob/ios/interstitial
func createAndLoadInterstitial() -> GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
interstitial.delegate = self
interstitial.load(GADRequest())
return interstitial
}

Swift 3, SpriteKit, Google Interstitial ad never ready

This question has been asked and answered multiple times here. And i've read them all, implemented all suggestions, and still it does not work. I'm currently doing it with a NotificationObserver and the ad is created, however it always returns false for isReady. Please let me know if anything sticks out.
GameViewController
var interstitial: GADInterstitial!
In viewDidLoad
interstitial = createAndLoadInterstitial()
NotificationCenter.default.addObserver(self, selector: #selector(self.showInterstitial), name:NSNotification.Name(rawValue: "showInterAd"), object: nil);
Ad functions
func showInterstitial(){
if (interstitial!.isReady) {
self.interstitial.present(fromRootViewController: self)
}else{
print("ad not ready?")
}
}
func createAndLoadInterstitial() -> GADInterstitial {
print("making ad")
let interstitial = GADInterstitial(adUnitID: "ca-app-pub-6956068899232786/9340371153")
interstitial.delegate = self
let request = GADRequest()
request.testDevices = [kGADSimulatorID]
interstitial.load(request)
return interstitial
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
interstitial = createAndLoadInterstitial()
}
GameScene.swift
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showInterAd"), object: nil)
All functions get called at correct times, but the ad just never becomes ready. I have triple checked the adUnitID, and tried on multiple devices/simulators.
So i've got it working. I do not know why this worked, and i'm assuming it has nothing to do with the app itself, but a bug or something within AdMob.
The fix was to replace the ad_unit_id with a different one from one of my other apps, which then made the ad become ready and display. I was then able to replace the ad_unit_id back to the correct one for this app and it still works.
It's like it needed one that had been used before to jumpstart it in to working. It's got me baffled, but hopefully this helps someone else.

My real AdMob adUnitID doesn't work but i can see test ones

EDITED: Okay so after googling a little bit more. I found this other stackoverflow post that says that it might even take 12 hours for the production AdMob to be activated. If that occurs, I will close this post.
I made an iOS game and I added some AdMob. Created the AdMob account, linked my game with the itunesconnect app info. So everything seemed to be working fine.
Afterwards, they give you the real adUnitID. But when I add it, it doesn't show up. Only when I use the test ones.
Why is that? am I doing something wrong ? or this is on purpose?
Here's my code:
var googleBannerView: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
self.googleBannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
self.googleBannerView.adUnitID = "ca-app-pub-3940256099942544/6300978111"
self.googleBannerView.rootViewController = self
//for testing simple : ca-app-pub-3940256099942544/6300978111
//for testing interstitial : ca-app-pub-3940256099942544/1033173712
//for production : ca-app-pub-6797599317996282/85919XXXXX
let request = GADRequest()
// request.testDevices = ["d0acc1d1423027d2d259f6bb2cbb9652"]
self.googleBannerView.loadRequest(request)
self.googleBannerView.frame = CGRectMake(0, self.view.bounds.height - self.googleBannerView.frame.size.height,
self.googleBannerView.frame.size.width, self.googleBannerView.frame.size.height)
// self.googleBannerView.hidden = true
self.view.addSubview(self.googleBannerView)
}
func adViewDidReceiveAd(bannerView: GADBannerView!) {
self.googleBannerView.hidden = false
}
func adView(bannerView: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) {
self.googleBannerView.hidden = true
}

iOS AdMob Reward Video

I'm trying to reward a user for watching a video with AdMob. Although I couldn't find any tutorial on the subject, I found these two classes in the documentation:
GADRewardBasedVideoAd
GADRewardBasedVideoAdDelegate
I've set up the display of a GADRewardBasedVideoAd with the following View Controller code:
class MarketController: UIViewController, GADRewardBasedVideoAdDelegate {
override func viewDidLoad() {
super.viewDidLoad()
GADRewardBasedVideoAd.sharedInstance().delegate = self
let request = GADRequest()
// Requests test ads on test devices.
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
GADRewardBasedVideoAd.sharedInstance().loadRequest(request, withAdUnitID: "ca-app-pub-3940256099942544/4411468910")
}
// MARK: Daily Reward Button Delegate
#IBAction func playVideoClicked() {
if GADRewardBasedVideoAd.sharedInstance().ready {
GADRewardBasedVideoAd.sharedInstance().presentFromRootViewController(self)
}
}
// MARK: GADRewardBasedVideoAdDelegate
func rewardBasedVideoAdDidStartPlaying(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
MediaPlayer.pauseBackgroundMusic()
print("Reward Video: Started")
}
func rewardBasedVideoAdDidClose(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
MediaPlayer.startBackgroundMusic()
requestLoadAd()
print("Reward Video: Complete")
}
func rewardBasedVideoAdWillLeaveApplication(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
requestLoadAd()
print("Reward Video: Will leave application")
}
}
When I press the button to trigger the code in the "playVideoClicked" function, I just see a regular test interstitial (no video) and the "rewardBasedVideoDidStartPlaying" function never gets called. When I close the interstitial the "rewardBasedVideoAdDidClose" function is called, though. Does this mean I did something wrong, or does AdMob just not display test videos?
Also, how do I configure this ad as a Reward Video in the AdMob developer console?
Change request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"] to request.testDevices = [kGADSimulatorID] and it should be working.

loading admob interstital ad when app launches using swift

I'm looking to find away to load an admob interstitial ad when my app launches. Just load one initial ad when the app launches. I'm using swift and can't seem to find any forms on how to do this.
import GoogleMobileAds
In Appdelegate Create function
func createAndLoadAd() -> GADInterstitial
{
var ad = GADInterstitial(adUnitID: "ca-app-pub-5018462886395219/7896492088")
var request = GADRequest()
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
ad.loadRequest(request)
return ad
}
In DidFinishLunchingMethod
self.interstitial = self.createAndLoadAd()
if (self.interstitial.isReady)
{
self.interstitial.presentFromRootViewController(self)
self.interstitial = self.createAndLoadAd()
}

Resources