native 多次调用show的定时刷新问题

This commit is contained in:
luojian 2025-10-20 13:35:35 +08:00
parent 7af1810cf9
commit d453b7b73d
1 changed files with 24 additions and 8 deletions

View File

@ -27,6 +27,7 @@ namespace WZ
private Dictionary<string, int> _retryCounters = new Dictionary<string, int>(); private Dictionary<string, int> _retryCounters = new Dictionary<string, int>();
private Dictionary<string, float> _adStartLoadTimes = new Dictionary<string, float>(); private Dictionary<string, float> _adStartLoadTimes = new Dictionary<string, float>();
private Dictionary<string, ShowNativePosition> showingNativeAds = new(); private Dictionary<string, ShowNativePosition> showingNativeAds = new();
private Dictionary<string, bool> TimingRefreshDict = new();
public void InitializeAdUnits(List<string> adUnitIds) public void InitializeAdUnits(List<string> adUnitIds)
{ {
@ -143,8 +144,8 @@ namespace WZ
ad.OnAdPaid += (AdValue adValue) => ad.OnAdPaid += (AdValue adValue) =>
{ {
LoggerUtils.Debug($"[Admob] Native ad paid {adValue.Value} {adValue.CurrencyCode}."); LoggerUtils.Debug($"[Admob] Native ad paid {adValue.Value} {adValue.CurrencyCode}.");
AdmobAdsManager.Instance.TrackAdImpression(ad?.GetResponseInfo()?.GetLoadedAdapterResponseInfo().AdSourceName??"", AdmobAdsManager.Instance.TrackAdImpression(ad?.GetResponseInfo()?.GetLoadedAdapterResponseInfo().AdSourceName ?? "",
ad?.GetResponseInfo()?.GetLoadedAdapterResponseInfo().AdSourceInstanceId??"", ad?.GetResponseInfo()?.GetLoadedAdapterResponseInfo().AdSourceInstanceId ?? "",
adValue, adValue,
AdsType.Native, AdsType.Native,
adUnitId); adUnitId);
@ -275,6 +276,16 @@ namespace WZ
private void TimingRefresh(string adUnitId) private void TimingRefresh(string adUnitId)
{ {
// 同一个id只允许触发一次定时刷新。 避免多次调用show ,多次来触发刷新
if (TimingRefreshDict.TryGetValue(adUnitId, out var timingRefresh))
{
if (timingRefresh)
{
LoggerUtils.Debug($"[Admob] Native ad ({adUnitId}) timing refresh finished. 正在刷新中.不用重复刷新.");
return;
}
}
var nativeReflashGap = int.Parse(FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("Native_Reflash_Gap", "0")); var nativeReflashGap = int.Parse(FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("Native_Reflash_Gap", "0"));
if (nativeReflashGap <= 0) if (nativeReflashGap <= 0)
@ -295,10 +306,15 @@ namespace WZ
return; return;
} }
LoggerUtils.Debug($"[Admob] Native ad ({adUnitId}) timing refresh start. nativeReflashGap = {nativeReflashGap}");
TimingRefreshDict.AddIfNotExists(adUnitId, true);
WLoom.QueueOnMainThread(o => WLoom.QueueOnMainThread(o =>
{ {
var refreshAdUnitId = (string)o; var refreshAdUnitId = (string)o;
LoggerUtils.Debug($"[Admob] Native ad ({adUnitId}) timing refresh load start refreshAdUnitId : {refreshAdUnitId}."); var remove = TimingRefreshDict.Remove(refreshAdUnitId);
LoggerUtils.Debug($"[Admob] Native ad ({adUnitId}) timing refresh load start refreshAdUnitId : {refreshAdUnitId}. TimingRefreshDict.Remove = {remove}");
if (showingNativeAds.ContainsKey(refreshAdUnitId)) if (showingNativeAds.ContainsKey(refreshAdUnitId))
{ {
LoadAd(refreshAdUnitId, true); LoadAd(refreshAdUnitId, true);
@ -332,10 +348,10 @@ namespace WZ
public string GetHighestPayingAdUnit() public string GetHighestPayingAdUnit()
{ {
return _adRevenueCache return _adRevenueCache
.Where(kvp => IsAdAvailable(kvp.Key)) .Where(kvp => IsAdAvailable(kvp.Key))
.OrderByDescending(kvp => kvp.Value) .OrderByDescending(kvp => kvp.Value)
.Select(kvp => kvp.Key) .Select(kvp => kvp.Key)
.FirstOrDefault(); .FirstOrDefault();
} }
// 获取价格最高的广告收益信息 // 获取价格最高的广告收益信息