Reputation: 789
In my application I applied Both test ads (banner and interstitial) they are showing perfectly but when I apply real ads Both of them did not display. I wait for 1 day and after one day only banner ads are showing now interstitial ads are not showing ( my ads id where generated 1 years before than why I need to wait 1 day to show in my application after uploading to google play store. Now how can I display Interstitial ads please?
class Afcon extends StatefulWidget {
final String link;
Afcon({this.link});
@override
_AfconState createState() => _AfconState();
}
class _AfconState extends State<Afcon> {
void initState() {
super.initState();
FirebaseAdMob.instance.initialize(appId: AppId);
bannerAd = buildBanner()..load();
interstitialAd = buildInterstitial()..load();
}
@override
Widget build(BuildContext context) {
bannerAd ..load()..show(
anchorOffset: 20.0,
anchorType: AnchorType.bottom,
);
Future<bool> _onBackPressed() {
if(counter<1){
interstitialAd
..load()..show();
counter++;
}
else{
bannerAd.dispose();
Navigator.pop(context, true);
}
}
return WillPopScope(
child: WebviewScaffold(
appBar: AppBar(
title: Text('AFCON'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.open_in_new),
onPressed: (){
_newPage(widget.link);
}
)
],
),
initialChild: SpinKitWave(
color: Colors.black,
size: 30.0,
),
hidden: true,
url: widget.link,
),
onWillPop: _onBackPressed,
);
}
}
_newPage(String link) async {
if (await canLaunch(link)) {
await launch(link);
} else {
throw 'Could not launch $link';
}
}
Here initialized the Functions to show ads
import 'package:firebase_admob/firebase_admob.dart';
final AppId='ca-app-pub-**********************';
final InterstitialAdsUnit='ca-app-pub-**********************';
final BannerAdsUnit='ca-app-pub-**********************';
int counter=0;
final MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: ['Games', 'Puzzles'],
);
BannerAd bannerAd;
InterstitialAd interstitialAd;
RewardedVideoAd rewardedVideoAd;
BannerAd buildBanner() {
return BannerAd(
adUnitId: BannerAdsUnit,
size: AdSize.banner,
listener: (MobileAdEvent event) {
print(event);
});
}
InterstitialAd buildInterstitial() {
return InterstitialAd(
adUnitId: InterstitialAdsUnit,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
if (event == MobileAdEvent.failedToLoad) {
interstitialAd..load();
} else if (event == MobileAdEvent.closed) {
interstitialAd = buildInterstitial()..load();
}
print(event);
});
}
Upvotes: 0
Views: 1104
Reputation: 513
Are you testing real ads on debug version of apk ? If yes, Please try testing in real device with signed version of apk. I've seen many times real ads don't show in debug version of apk.
Upvotes: 1
Reputation: 602
You have done everything perfectly from your side now you need to check the interstitial ads unit Id I am sure you have issue with ads unit ID. Go and make some new test Id and implement it on your app it will work. after applying new ads unit just wait sometime to let them show.
Upvotes: 1
Reputation: 178
Never test your own ad, always use test ad units,
If you create a new admob app id, it might take some time for these ad units to go live, so it won't show ad.
So, if you run test ad units, does it work in real device?
Upvotes: 1