update: 优化广告加载逻辑和 Loading 锁

deeplink 1.0.10
胡宇飞 2024-04-09 21:32:28 +08:00
parent 07818bd40e
commit aced9b0d1d
2 changed files with 25 additions and 9 deletions

View File

@ -124,6 +124,7 @@ namespace Guru
public override void RequestInterstitialAD()
{
if (!IsInitialized) return;
if (IsIadsLoading) return;
OnChannelLoadInterstitialAD();
}
@ -154,6 +155,7 @@ namespace Guru
public override void RequestRewardedAD()
{
if (!IsInitialized) return;
if (IsRadsLoading) return;
OnChannelLoadRewardAD();
}

View File

@ -342,11 +342,15 @@ namespace Guru
private int _interstitialRetryAttempt;
protected float _iadsLoadStartTime;
private Action _interstitialDismissAction;
protected bool _isIadsLoading = false;
public bool IsIadsLoading => _isIadsLoading;
public virtual void RequestInterstitialAD()
{
if (!CanLoadAds())
return;
if (!CanLoadAds()) return;
if(_isIadsLoading) return;
_isIadsLoading = true;
LoadMaxInterstitial();
}
@ -368,9 +372,7 @@ namespace Guru
public bool IsInterstitialADReady()
{
if (!IsInitialized)
return false;
if (!IsInitialized) return false;
return MaxSdk.IsInterstitialReady(GetInterstitialID());
}
@ -398,11 +400,12 @@ namespace Guru
_interstitialDismissAction = dismissAction;
MaxSdk.ShowInterstitial(GetInterstitialID());
RequestInterstitialAD(); // 直接加载下一个广告
// RequestInterstitialAD(); // 直接加载下一个广告
}
protected virtual void OnInterstitialLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
_isIadsLoading = false;
// Interstitial ad is ready to be shown. MaxSdk.IsInterstitialReady(interstitialAdUnitId) will now return 'true'
// Reset retry attempt
// Analytics.ADIadsLoaded(adUnitId, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory);
@ -415,6 +418,7 @@ namespace Guru
protected virtual void OnInterstitialFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
_isIadsLoading = false;
// Interstitial ad failed to load
// We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds)
this.LogError(
@ -477,12 +481,16 @@ namespace Guru
private Action _rewardAction;
private Action<string> _failAction;
private Action _dismissAction;
protected bool _isRadsLoading = false;
public bool IsRadsLoading => _isRadsLoading;
public virtual void RequestRewardedAD()
{
if (!IsInitialized)
return;
if (!CanLoadAds()) return;
if (_isRadsLoading) return;
_isRadsLoading = true;
LoadMaxRewardAd();
}
@ -492,6 +500,8 @@ namespace Guru
/// </summary>
protected void LoadMaxRewardAd(string unitId = "")
{
if (IsRadsLoading) return;
OnLoadRads();
var id = GetRewardedVideoID();
Analytics.ADRadsLoad(AdParams.Build(id)); // 上报打点
@ -539,11 +549,13 @@ namespace Guru
_dismissAction = dismissAction;
MaxSdk.ShowRewardedAd(GetRewardedVideoID());
RequestRewardedAD();
// RequestRewardedAD();
}
protected virtual void OnRewardedAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
_isRadsLoading = false;
// Rewarded ad is ready to be shown. MaxSdk.IsRewardedAdReady(rewardedAdUnitId) will now return 'true'
// Reset retry attempt
// this.Log("OnRewardedAdLoadedEvent");
@ -557,6 +569,8 @@ namespace Guru
protected virtual void OnRewardedAdFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
_isRadsLoading = false;
// Rewarded ad failed to load
// We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds)
this.LogError(