Fix TapADN ad lifecycle callbacks

This commit is contained in:
2026-06-04 17:24:54 +08:00
parent d88855e35e
commit 02cb90c1c0
4 changed files with 119 additions and 7 deletions

View File

@@ -752,6 +752,11 @@ namespace Dirichlet.Mediation
/// </summary>
public event Action Closed;
/// <summary>
/// Raised when the native layer reports that a loaded ad failed to show.
/// </summary>
public event Action<DirichletError> ShowFailed;
internal DirichletAd(IDirichletPlatformBridge bridge, DirichletPlatformAdHandle platformHandle, long spaceId)
{
this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));
@@ -812,6 +817,9 @@ namespace Dirichlet.Mediation
case DirichletNativeEventNames.Close:
OnClosed();
break;
case DirichletNativeEventNames.ShowError:
OnShowFailed(nativeEvent.Data);
break;
}
}
@@ -829,6 +837,13 @@ namespace Dirichlet.Mediation
{
Closed?.Invoke();
}
protected virtual void OnShowFailed(DirichletNativeEventData data)
{
var code = data != null && data.Code != 0 ? data.Code.ToString(CultureInfo.InvariantCulture) : "show_error";
var message = data?.Message;
ShowFailed?.Invoke(new DirichletError(code, string.IsNullOrEmpty(message) ? "Ad failed to show" : message));
}
}
public abstract class DirichletRewardAdBase : DirichletAd
@@ -1085,6 +1100,7 @@ namespace Dirichlet.Mediation
internal const string Click = "click";
internal const string Close = "close";
internal const string Reward = "reward";
internal const string ShowError = "show_error";
}
internal readonly struct DirichletNativeEvent
@@ -1373,4 +1389,3 @@ namespace Dirichlet.Mediation
}
}