performShow method
Implementation
@override
Future<void> performShow(AppOpenAd ad, {AdOptions? options, AdCallBack? adCallBack}) async {
if (!_isAppOpenAdEnabled) {
LogUtils.w('$adsType: App Open Ad is disabled, skipping show');
ad.dispose();
_isShowingAd = false;
return;
}
void disposeAd() {
ad.dispose();
_isShowingAd = false;
_isAdAvailable = false;
// 当前广告消费完成后,异步补一个新的缓存,供下次前台展示使用。
if (_enableAutoCache) {
preloadAds(1);
}
}
if (!_shouldShowAppOpenAd) {
LogUtils.w('$adsType: Should not show App Open Ad, skipping');
restorePreloadedAd(ad, toFront: true);
return;
}
if (_isShowingAd) {
LogUtils.d("$adsType already showing");
// 当前已经有开屏广告在展示,新的广告先放回缓存头部,避免白白丢掉。
restorePreloadedAd(ad, toFront: true);
return;
}
if (_isAdExpired) {
LogUtils.d("$adsType expired (loaded at $_appOpenLoadTime)");
disposeAd();
return;
}
ad.fullScreenContentCallback = getCallback(
adCallBack,
onAdShowedFullScreenContent: (ad) {
_isShowingAd = true;
_setLastAdShownTime();
LogUtils.d("$adsType ad showed");
adCallBack?.onAdShown?.call(adsType);
},
onAdFailedToShowFullScreenContent: (ad, error) {
LogUtils.e("$adsType ad failed to show", error: error);
adCallBack?.onAdShowFailed?.call(adsType);
disposeAd();
},
onAdDismissedFullScreenContent: (ad) {
LogUtils.d("$adsType ad dismissed");
adCallBack?.onAdDismissed?.call(adsType);
disposeAd();
},
);
ad.onPaidEvent = notifyAdRevenue;
ad.show();
}