在 firebase_admob 插件被弃用后,我最近为 Flutter 集成了 google_mobile_ads 插件。从那时起,我的奖励广告就停止工作了。这些是我得到的错误:
(13077):此请求是从测试设备发送的。 E/chromium(13077): [ERROR:cookie_manager.cc(137)] 严格的安全 Cookie 政策不允许为目标 >= R 的应用设置 http://googleads.g.doubleclick.net/ 的安全 cookie。请使用“https:”方案为此 URL 或省略 cookie 值中的“安全”指令。 W/Ads (13077): #004 webview 被破坏。忽略操作。
我的代码如下:
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
InAppPurchaseConnection.enablePendingPurchases();
runApp(MyApp());
}
class _RewardedVideoState extends State<RewardedVideo> {
bool _rewardedReady = false;
RewardedAd _rewardedAd;
static final AdRequest _adRequest = AdRequest(
keywords: <String>['Puzzles', 'Games', 'Word Games'],
nonPersonalizedAds: true,
);
@override
void didChangeDependencies() {
createRewardedAd();
super.didChangeDependencies();
}
void createRewardedAd([Score userScore]) {
print('Inside createRewardedAd');
// RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("CFA70A4A1BD59DA3323D586CA8BD2541"))
_rewardedAd = RewardedAd(
adUnitId: RewardedAd.testAdUnitId,
request: _adRequest,
listener: AdListener(
onAdLoaded: (Ad ad) {
print('${ad.runtimeType} loaded. RADHA ');
_rewardedReady = true;
},
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('${ad.runtimeType} failed to load: $error');
ad.dispose();
_rewardedAd = null;
createRewardedAd(userScore);
},
onAdOpened: (Ad ad) => print('${ad.runtimeType} onAdOpened.'),
onAdClosed: (Ad ad) {
print('${ad.runtimeType} closed.');
ad.dispose();
createRewardedAd(userScore);
},
onApplicationExit: (Ad ad) =>
print('${ad.runtimeType} onApplicationExit.'),
onRewardedAdUserEarnedReward: (RewardedAd ad, RewardItem reward) {
userScore.updateHintsEarned(reward.amount);
}),
)..load();
print('Completed RewardedAd Load ' + _rewardedAd.toString());
}
@override
void dispose() {
_rewardedAd.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final Score userScore = Provider.of<Score>(context, listen: false);
print('Inside RewardedVideo widget *** ........');
try {
if (_rewardedReady) {
print('Showing rewardedAd ***');
_rewardedAd.show();
_rewardedReady = false;
_rewardedAd = null;
} else
createRewardedAd(userScore);
} catch (e) {
print("error in showing ad: " + e.toString());
}
return SizedBox(
height: 0,
);
}
}
我能够获得横幅广告(未包含在此代码中),但根本无法加载奖励广告。 知道这里可能出了什么问题吗?