flutter - Flutter,Facebook Audience Network 广告横幅在进入另一个屏幕时不显示
问题描述
我用这个插件
facebook_audience_network 0.5.0
我通过这种方式实现了这个
class FacebookAd{
static void faceInit() {
FacebookAudienceNetwork.init(
testingId: "xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx",
);
}
static widget myBanner;
static void showBannerAd() {
myBanner = FacebookBannerAd(
placementId: "xxxxxxxxx_xxxxxxxxxxx",
keepAlive: true,
bannerSize: BannerSize.STANDARD,
listener: (result, value) {
print("Banner Ad: $result --> $value eee");
switch (result) {
case BannerAdResult.ERROR:
print("Error: $value");
break;
case BannerAdResult.LOADED:
print("Loaded: $value");
break;
case BannerAdResult.CLICKED:
print("Clicked: $value");
break;
case BannerAdResult.LOGGING_IMPRESSION:
print("Logging Impression: $value");
break;
}
},
);
}
}
}
和其他班级
return Scaffold(
bottomNavigationBar: FacebookAd.myBanner
)
所以在应用程序中,所有屏幕都引用变量“myBanner”以在“bottomNavigationBar”内显示横幅
但问题是使用 pushNamed("/xxx") 更改屏幕时
有时屏幕显示横幅,有时不显示!(大部分不是)
我该如何解决这个问题?
谢谢你
解决方案
以下是我解决不同页面的 FAN 插页式广告的方法,与 AdMob 不同,您应该在单独的 dart 类中集中管理 Facebook FAN 广告。
class MyFacebookAdsManager {
static bool isInterstitialAdLoaded = false;
static String adsInterstitialUnitId = '';
static void init(String id) {
logger.i('$prefix init called');
adsInterstitialUnitId = id;
FacebookAudienceNetwork.init(
testingId: '<test-id-if-needed>',
);
loadNewFANInterstitialAd();
}
static void loadNewFANInterstitialAd() {
FacebookInterstitialAd.loadInterstitialAd(
placementId: adsInterstitialUnitId,
listener: (result, value) {
logger.i("$prefix >> FAN > Interstitial Ad: $result --> $value");
switch (result) {
case InterstitialAdResult.LOADED:
isInterstitialAdLoaded = true;
break;
case InterstitialAdResult.DISMISSED:
isInterstitialAdLoaded = false;
loadNewFANInterstitialAd();
break;
case InterstitialAdResult.ERROR:
isInterstitialAdLoaded = false;
logger.e('error loading facebook ads');
loadNewFANInterstitialAd();
break;
default:
}
},
);
}
static void showInterstitialAd() {
if (isInterstitialAdLoaded)
FacebookInterstitialAd.showInterstitialAd();
else
loadNewFANInterstitialAd();
}
}
现在在主屏幕中,您将调用一次且仅一次的 init。
MyFacebookAdsManager.init('test-id')
最后,无论您想在哪里展示广告,都可以使用创建的类并展示广告。
MyFacebookAdsManager.showInterstitialAd();
以同样的方式,您应该创建单独的课程并管理所有横幅和奖励视频。
推荐阅读
- r - 删除 geom_tile 中的空白并匹配 geom_vline&hline 位置
- c# - 无法解析“Jabberwocky.Core.Caching.ICacheProvider”类型的服务
- python - 根据行相关和列相关条件设置数据框值
- python - Python:我有一个日期列表。我想计算到当前日期的天数
- sql - 仅匹配 Redshift Regex 中的百分比值
- mysql - 安装 MySQL 服务器 8.0.14 失败
- bookshelf.js - Strapi:查询图像
- r - 在数据框中创建一个新列,其值基于另一列
- php - 如何提取像 &\#1071; 这样的 Unicode 字符 来自羽毛笔编辑器的 INNERHTML 的“Я”?
- html - 为什么 ui-dialog z-index 不改变?