我正在尝试在我的应用中实施广告。目前我正在研究 Google Ad Mobs Rewarded Video Ads。我的问题是,在我第一次按下应该加载广告的按钮后,错误变为:
未处理的异常:PlatformException(ad_not_loaded,奖励视频显示失败,未加载广告,null)
被抛出,但如果我再次按下它会正常工作。我附上了一些相关的代码
设置定位信息,加载广告并创建监听器:
@override
void initState() {
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
);
RewardedVideoAd.instance.load(
targetingInfo: targetingInfo,
adUnitId: RewardedVideoAd.testAdUnitId);
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.rewarded) {
Navigator.push(
context,
this.route);
}
else if(event == RewardedVideoAdEvent.failedToLoad){
Navigator.push(
context,
this.route);
}
};
super.initState();
}
启动广告的 Button(位于同一类的 build 方法中):
GestureDetector(
child: AdButton(theme.wopGH, "Gratis spielen"),
onTap: () {
RewardedVideoAd.instance.show();
},
),