Yandex Mobile Ads
Loading...
Searching...
No Matches
AppOpenAdLoader.cs
Go to the documentation of this file.
1/*
2 * This file is a part of the Yandex Advertising Network
3 *
4 * Version for Unity (C) 2023 YANDEX
5 *
6 * You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
8 */
9
10using System;
12using YandexMobileAds.Common;
13using YandexMobileAds.Platforms;
14
15namespace YandexMobileAds
16{
20 public class AppOpenAdLoader
21 {
25 public event EventHandler<AppOpenAdLoadedEventArgs> OnAdLoaded;
26
30 public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
31
32 private readonly AdRequestConfigurationFactory _adRequestConfigurationFactory;
33 private readonly IAppOpenAdLoaderClient _client;
34
39 {
40 this._adRequestConfigurationFactory = new AdRequestConfigurationFactory();
41 this._client = YandexMobileAdsClientFactory.BuildAppOpenAdLoaderClient();
42
43 MainThreadDispatcher.initialize();
44 ConfigureAppOpenAdEvents();
45 }
46
52 public void LoadAd(AdRequestConfiguration configuration)
53 {
54 _client.LoadAd(_adRequestConfigurationFactory.CreateAdRequestConfiguration(configuration));
55 }
56
60 public void CancelLoading()
61 {
62 this._client.CancelLoading();
63 }
64
65 private void ConfigureAppOpenAdEvents()
66 {
67 this._client.OnAdLoaded += (sender, args) =>
68 {
69 if (this.OnAdLoaded == null)
70 {
71 return;
72 }
73
74 MainThreadDispatcher.EnqueueAction(() =>
75 {
76 if (this.OnAdLoaded == null)
77 {
78 return;
79 }
80
81 AppOpenAdLoadedEventArgs adLoadedEventArgs = new AppOpenAdLoadedEventArgs()
82 {
83 AppOpenAd = new AppOpenAd(args.Value)
84 };
85 this.OnAdLoaded(this, adLoadedEventArgs);
86 });
87 };
88
89 this._client.OnAdFailedToLoad += (sender, args) =>
90 {
91 if (this.OnAdFailedToLoad == null)
92 {
93 return;
94 }
95
96 MainThreadDispatcher.EnqueueAction(() =>
97 {
98 if (this.OnAdFailedToLoad == null)
99 {
100 return;
101 }
102
103 this.OnAdFailedToLoad(this, args);
104 });
105 };
106 }
107 }
108}
Full-screen app open ad.
Definition AppOpenAd.cs:20
Full-screen app open ads.
EventHandler< AppOpenAdLoadedEventArgs > OnAdLoaded
Notifies that ad is loaded.
void LoadAd(AdRequestConfiguration configuration)
Starts loading the ad by AdRequestConfiguration. A successfuly loaded AppOpenAd will be delivered via...
void CancelLoading()
Cancel active loading of the rewarded ads.
EventHandler< AdFailedToLoadEventArgs > OnAdFailedToLoad
Notifies that an app open ad request failed.
AppOpenAdLoader()
Cunstructs an object of the AppOpenAdLoader class.
A class with data for a targeted ad request.