From 72bf07653724a94804d6a2023df9b8a29eea9237 Mon Sep 17 00:00:00 2001 From: huyufei Date: Tue, 16 Jul 2024 18:46:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=20=E5=B9=BF=E5=91=8A=20SDK=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B9=BF=E5=91=8A=E9=87=8D=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E9=97=B4=20=E4=BB=8E=E6=9C=80=E9=AB=98=E9=97=B4=E9=9A=94=208?= =?UTF-8?q?=20=E7=A7=92=20->=2064=20=E7=A7=92=EF=BC=8C=20=E5=87=8F?= =?UTF-8?q?=E5=B0=91=E6=97=A0=E7=BD=91=E6=97=B6=E9=AB=98=E9=A2=91=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1020971 --user=yufei.hu 【中台】【ADS】优化 IV 和 RV 广告加载失败后的重试等待时间 https://www.tapd.cn/33527076/s/1157502 Signed-off-by: huyufei --- Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs b/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs index 2204d98..7169ba6 100644 --- a/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs +++ b/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs @@ -22,6 +22,8 @@ namespace Guru public bool IsInitialized => MaxSdk.IsInitialized() || _isServiceStarted; protected bool IsNetworkEnabled => Application.internetReachability != NetworkReachability.NotReachable; + private const int MAX_ADS_RELOAD_INTERVAL = 6; // 广告加载最高时间为 2 的 6 次方 = 64秒 + private bool _isServiceStarted; protected Action _onSdkInitReady; @@ -149,6 +151,13 @@ namespace Guru set => Model.BuyNoAds = value; } + private float GetRetryDelaySeconds(int retryCount) + { + // 最低 2^retryCount 秒 + // 最高 2^6 = 64 秒 + return (float)Math.Pow(2, Math.Min(MAX_ADS_RELOAD_INTERVAL, retryCount)); + } + #region Lifecycele public void OnAppPaused(bool paused) @@ -511,8 +520,8 @@ namespace Guru this.LogError( $"OnInterstitialFailedEvent AdLoadFailureInfo:{errorInfo.AdLoadFailureInfo}, Message: {errorInfo.Message}"); _interstitialRetryAttempt++; - double retryDelay = Math.Pow(2, Math.Min(3, _interstitialRetryAttempt)); - DelayCall((float)retryDelay, RequestInterstitialAD); + float retryDelay = GetRetryDelaySeconds(_interstitialRetryAttempt); + DelayCall(retryDelay, RequestInterstitialAD); // Analytics.ADIadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory); Analytics.ADIadsFailed(AdParams.Build(adUnitId, duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory, @@ -669,8 +678,8 @@ namespace Guru errorCode: (int)errorInfo.Code, waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); _rewardRetryAttempt++; - double retryDelay = Math.Pow(2, Math.Min(3, _rewardRetryAttempt)); - DelayCall((float)retryDelay, RequestRewardedAD); + float retryDelay = GetRetryDelaySeconds(_rewardRetryAttempt); + DelayCall(retryDelay, RequestRewardedAD); OnRewardFailed?.Invoke(); }