Hi All, This is Aliza. Actually I have an issue related to admob with ionic 4. I wanna display ads in my application. Therefore I created my admob account here: https://apps.admob.com/v2/ .
But my account has an problem, it shows that ads on my account are limited. here is the screenshort:
after that here is my ionic code which is responsible for ads:
import {Injectable} from '@angular/core';
import { Platform } from '@ionic/angular';
import {AdMobFree, AdMobFreeInterstitialConfig, AdMobFreeBannerConfig} from '@ionic-native/admob-free/ngx';
import {AdMobFreeRewardVideoConfig} from '@ionic-native/admob-free/ngx';
@Injectable({
providedIn: 'root'
})
export class AdmobService {
// Interstitial Ad's Configurations
interstitialConfig: AdMobFreeInterstitialConfig = {
// add your config here
// for the sake of this example we will just use the test config
isTesting: true,
autoShow: false,
id: 'ca-app-pub-6609486675383816/2586963648'
};
// Reward Video Ad's Configurations
RewardVideoConfig: AdMobFreeRewardVideoConfig = {
isTesting: true, // Remove in production
autoShow: false,
id: 'ca-app-pub-6609486675383816/3439551324'
};
constructor(
private admobFree: AdMobFree,
public platform: Platform
) {
platform.ready().then(() => {
// Load ad configuration
this.admobFree.interstitial.config(this.interstitialConfig);
// Prepare Ad to Show
this.admobFree.interstitial.prepare()
.then(() => {
// console.log(1);
}).catch(e => console.log(e));
// Load ad configuration
this.admobFree.rewardVideo.config(this.RewardVideoConfig);
// Prepare Ad to Show
this.admobFree.rewardVideo.prepare()
.then(() => {
// console.log(2);
}).catch(e => console.log(e));
});
// Handle interstitial's close event to Prepare Ad again
this.admobFree.on('admob.interstitial.events.CLOSE').subscribe(() => {
this.admobFree.interstitial.prepare()
.then(() => {
console.log('Interstitial CLOSE');
}).catch(e => console.log(e));
});
// Handle Reward's close event to Prepare Ad again
this.admobFree.on('admob.rewardvideo.events.CLOSE').subscribe(() => {
this.admobFree.rewardVideo.prepare()
.then(() => {
console.log('Reward Video CLOSE');
}).catch(e => console.log(e));
});
}
BannerAd() {
const bannerConfig: AdMobFreeBannerConfig = {
isTesting: true, // Remove in production
autoShow: true,
id: 'ca-app-pub-6609486675383816/3718768832'
};
this.admobFree.banner.config(bannerConfig);
this.admobFree.banner.prepare().then(() => {
console.log('Done');
}).catch(e => console.log(e));
}
InterstitialAd() {
// Check if Ad is loaded
this.admobFree.interstitial.isReady().then(() => {
// Will show prepared Ad
this.admobFree.interstitial.show().then(() => {
})
.catch(e => console.log('show ' + e));
})
.catch(e => console.log('isReady ' + e));
}
RewardVideoAd() {
// Check if Ad is loaded
this.admobFree.rewardVideo.isReady().then(() => {
// Will show prepared Ad
this.admobFree.rewardVideo.show().then(() => {
})
.catch(e => console.log('show ' + e));
})
.catch(e => console.log('isReady ' + e));
}
}
I tried this with live reload and in the console logs. I get the error with the name of ads are not ready yet.
Please help me if you can.
Best regards!
Aliza.