GADUInterface.m 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. // Copyright 2014 Google Inc. All Rights Reserved.
  2. #import "GADUAdLoader.h"
  3. #import "GADUBanner.h"
  4. #import "GADUInterstitial.h"
  5. #import "GADUNativeCustomTemplateAd.h"
  6. #import "GADUPluginUtil.h"
  7. #import <GoogleMobileAds/GoogleMobileAds.h>
  8. #import "GADUAdNetworkExtras.h"
  9. #import "GADUObjectCache.h"
  10. #import "GADURequest.h"
  11. #import "GADURequestConfiguration.h"
  12. #import "GADURewardBasedVideoAd.h"
  13. #import "GADURewardedAd.h"
  14. #import "GADURewardedInterstitialAd.h"
  15. #import "GADUTypes.h"
  16. /// Returns an NSString copying the characters from |bytes|, a C array of UTF8-encoded bytes.
  17. /// Returns nil if |bytes| is NULL.
  18. static NSString *GADUStringFromUTF8String(const char *bytes) { return bytes ? @(bytes) : nil; }
  19. /// Returns a C string from a C array of UTF8-encoded bytes.
  20. static const char *cStringCopy(const char *string) {
  21. if (!string) {
  22. return NULL;
  23. }
  24. char *res = (char *)malloc(strlen(string) + 1);
  25. strcpy(res, string);
  26. return res;
  27. }
  28. /// Returns a C string from a C array of UTF8-encoded bytes.
  29. static const char **cStringArrayCopy(NSArray *array) {
  30. if (array == nil) {
  31. return nil;
  32. }
  33. const char **stringArray;
  34. stringArray = calloc(array.count, sizeof(char *));
  35. for (int i = 0; i < array.count; i++) {
  36. stringArray[i] = cStringCopy([array[i] UTF8String]);
  37. }
  38. return stringArray;
  39. }
  40. /// Defines the native ad types.
  41. struct AdTypes {
  42. int CustomTemplateAd;
  43. };
  44. /// Configures the SDK using the settings associated with the given application ID.
  45. void GADUInitialize(const char *appId) {
  46. [GADMobileAds configureWithApplicationID:GADUStringFromUTF8String(appId)];
  47. }
  48. void GADUInitializeWithCallback(GADUTypeMobileAdsClientRef *mobileAdsClientRef,
  49. GADUInitializationCompleteCallback callback) {
  50. [[GADMobileAds sharedInstance]
  51. startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status) {
  52. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  53. cache[status.gadu_referenceKey] = status;
  54. callback(mobileAdsClientRef, (__bridge GADUTypeInitializationStatusRef)status);
  55. }];
  56. }
  57. void GADUDisableMediationInitialization() {
  58. [[GADMobileAds sharedInstance] disableMediationInitialization];
  59. }
  60. const char *GADUGetInitDescription(GADUTypeInitializationStatusRef statusRef,
  61. const char *className) {
  62. GADInitializationStatus *status = (__bridge GADInitializationStatus *)statusRef;
  63. GADAdapterStatus *adapterStatus =
  64. status.adapterStatusesByClassName[GADUStringFromUTF8String(className)];
  65. return cStringCopy(adapterStatus.description.UTF8String);
  66. }
  67. int GADUGetInitLatency(GADUTypeInitializationStatusRef statusRef, const char *className) {
  68. GADInitializationStatus *status = (__bridge GADInitializationStatus *)statusRef;
  69. GADAdapterStatus *adapterStatus =
  70. status.adapterStatusesByClassName[GADUStringFromUTF8String(className)];
  71. return adapterStatus.latency;
  72. }
  73. int GADUGetInitState(GADUTypeInitializationStatusRef statusRef, const char *className) {
  74. GADInitializationStatus *status = (__bridge GADInitializationStatus *)statusRef;
  75. GADAdapterStatus *adapterStatus =
  76. status.adapterStatusesByClassName[GADUStringFromUTF8String(className)];
  77. return (int)adapterStatus.state;
  78. }
  79. const char **GADUGetInitAdapterClasses(GADUTypeInitializationStatusRef statusRef) {
  80. GADInitializationStatus *status = (__bridge GADInitializationStatus *)statusRef;
  81. NSDictionary<NSString *, GADAdapterStatus *> *map = status.adapterStatusesByClassName;
  82. NSArray<NSString *> *classes = map.allKeys;
  83. return cStringArrayCopy(classes);
  84. }
  85. int GADUGetInitNumberOfAdapterClasses(GADUTypeInitializationStatusRef statusRef) {
  86. GADInitializationStatus *status = (__bridge GADInitializationStatus *)statusRef;
  87. NSDictionary<NSString *, GADAdapterStatus *> *map = status.adapterStatusesByClassName;
  88. NSArray<NSString *> *classes = map.allKeys;
  89. return (int)classes.count;
  90. }
  91. // The application’s audio volume. Affects audio volumes of all ads relative to
  92. // other audio output. Valid ad volume values range from 0.0 (silent) to 1.0
  93. // (current device volume). Use this method only if your application has its own
  94. // volume controls (e.g., custom music or sound effect volumes). Defaults
  95. // to 1.0.
  96. void GADUSetApplicationVolume(float volume) {
  97. [[GADMobileAds sharedInstance] setApplicationVolume:volume];
  98. }
  99. // Indicates if the application’s audio is muted. Affects initial mute state for
  100. // all ads. Use this method only if your application has its own volume controls
  101. // (e.g., custom music or sound effect muting). Defaults to NO.
  102. void GADUSetApplicationMuted(BOOL muted) {
  103. [[GADMobileAds sharedInstance] setApplicationMuted:muted];
  104. }
  105. // Indicates if the Unity app should be paused when a full screen ad (interstitial
  106. // or rewarded video ad) is displayed.
  107. void GADUSetiOSAppPauseOnBackground(BOOL pause) { [GADUPluginUtil setPauseOnBackground:pause]; }
  108. float GADUDeviceScale() {
  109. return UIScreen.mainScreen.scale;
  110. }
  111. /// Returns the safe width of the device.
  112. int GADUDeviceSafeWidth() {
  113. CGRect screenBounds = [UIScreen mainScreen].bounds;
  114. if (GADUIsOperatingSystemAtLeastVersion(11)) {
  115. CGRect safeFrame = [UIApplication sharedApplication].keyWindow.safeAreaLayoutGuide.layoutFrame;
  116. if (!CGSizeEqualToSize(safeFrame.size, CGSizeZero)) {
  117. screenBounds = safeFrame;
  118. }
  119. }
  120. return (int)CGRectGetWidth(screenBounds);
  121. }
  122. /// Creates a GADBannerView with the specified width, height, and position. Returns a reference to
  123. /// the GADUBannerView.
  124. GADUTypeBannerRef GADUCreateBannerView(GADUTypeBannerClientRef *bannerClient, const char *adUnitID,
  125. NSInteger width, NSInteger height,
  126. GADAdPosition adPosition) {
  127. GADUBanner *banner =
  128. [[GADUBanner alloc] initWithBannerClientReference:bannerClient
  129. adUnitID:GADUStringFromUTF8String(adUnitID)
  130. width:(int)width
  131. height:(int)height
  132. adPosition:adPosition];
  133. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  134. cache[banner.gadu_referenceKey] = banner;
  135. return (__bridge GADUTypeBannerRef)banner;
  136. }
  137. /// Creates a GADBannerView with the specified width, height, and custom position. Returns
  138. /// a reference to the GADUBannerView.
  139. GADUTypeBannerRef GADUCreateBannerViewWithCustomPosition(GADUTypeBannerClientRef *bannerClient,
  140. const char *adUnitID, NSInteger width,
  141. NSInteger height, NSInteger x,
  142. NSInteger y) {
  143. CGPoint adPosition = CGPointMake(x, y);
  144. GADUBanner *banner =
  145. [[GADUBanner alloc] initWithBannerClientReference:bannerClient
  146. adUnitID:GADUStringFromUTF8String(adUnitID)
  147. width:(int)width
  148. height:(int)height
  149. customAdPosition:adPosition];
  150. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  151. cache[banner.gadu_referenceKey] = banner;
  152. return (__bridge GADUTypeBannerRef)banner;
  153. }
  154. /// Creates a full-width GADBannerView in the current orientation. Returns a reference to the
  155. /// GADUBannerView.
  156. GADUTypeBannerRef GADUCreateSmartBannerView(GADUTypeBannerClientRef *bannerClient,
  157. const char *adUnitID, GADAdPosition adPosition) {
  158. GADUBanner *banner = [[GADUBanner alloc]
  159. initWithSmartBannerSizeAndBannerClientReference:bannerClient
  160. adUnitID:GADUStringFromUTF8String(adUnitID)
  161. adPosition:adPosition];
  162. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  163. cache[banner.gadu_referenceKey] = banner;
  164. return (__bridge GADUTypeBannerRef)banner;
  165. }
  166. /// Creates a full-width GADBannerView in the current orientation with a custom position. Returns a
  167. /// reference to the GADUBannerView.
  168. GADUTypeBannerRef GADUCreateSmartBannerViewWithCustomPosition(GADUTypeBannerClientRef *bannerClient,
  169. const char *adUnitID, NSInteger x,
  170. NSInteger y) {
  171. CGPoint adPosition = CGPointMake(x, y);
  172. GADUBanner *banner = [[GADUBanner alloc]
  173. initWithSmartBannerSizeAndBannerClientReference:bannerClient
  174. adUnitID:GADUStringFromUTF8String(adUnitID)
  175. customAdPosition:adPosition];
  176. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  177. cache[banner.gadu_referenceKey] = banner;
  178. return (__bridge GADUTypeBannerRef)banner;
  179. }
  180. /// Creates a an adaptive sized GADBannerView with the specified width, orientation, and position.
  181. /// Returns a reference to the GADUBannerView.
  182. GADUTypeBannerRef GADUCreateAnchoredAdaptiveBannerView(GADUTypeBannerClientRef *bannerClient,
  183. const char *adUnitID, NSInteger width,
  184. GADUBannerOrientation orientation,
  185. GADAdPosition adPosition) {
  186. GADUBanner *banner = [[GADUBanner alloc]
  187. initWithAdaptiveBannerSizeAndBannerClientReference:bannerClient
  188. adUnitID:GADUStringFromUTF8String(adUnitID)
  189. width:(int)width
  190. orientation:orientation
  191. adPosition:adPosition];
  192. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  193. cache[banner.gadu_referenceKey] = banner;
  194. return (__bridge GADUTypeBannerRef)banner;
  195. }
  196. /// Creates a an adaptive sized GADBannerView with the specified width, orientation, and position.
  197. /// Returns a reference to the GADUBannerView.
  198. GADUTypeBannerRef GADUCreateAnchoredAdaptiveBannerViewWithCustomPosition(
  199. GADUTypeBannerClientRef *bannerClient, const char *adUnitID, NSInteger width,
  200. GADUBannerOrientation orientation, NSInteger x, NSInteger y) {
  201. CGPoint adPosition = CGPointMake(x, y);
  202. GADUBanner *banner = [[GADUBanner alloc]
  203. initWithAdaptiveBannerSizeAndBannerClientReference:bannerClient
  204. adUnitID:GADUStringFromUTF8String(adUnitID)
  205. width:(int)width
  206. orientation:orientation
  207. customAdPosition:adPosition];
  208. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  209. cache[banner.gadu_referenceKey] = banner;
  210. return (__bridge GADUTypeBannerRef)banner;
  211. }
  212. /// Creates a GADUInterstitial and returns its reference.
  213. GADUTypeInterstitialRef GADUCreateInterstitial(GADUTypeInterstitialClientRef *interstitialClient,
  214. const char *adUnitID) {
  215. GADUInterstitial *interstitial = [[GADUInterstitial alloc]
  216. initWithInterstitialClientReference:interstitialClient
  217. adUnitID:GADUStringFromUTF8String(adUnitID)];
  218. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  219. cache[interstitial.gadu_referenceKey] = interstitial;
  220. return (__bridge GADUTypeInterstitialRef)interstitial;
  221. }
  222. /// Creates a GADURewardBasedVideo and returns its reference.
  223. GADUTypeRewardBasedVideoAdRef GADUCreateRewardBasedVideoAd(
  224. GADUTypeRewardBasedVideoAdClientRef *rewardBasedVideoAdClient) {
  225. GADURewardBasedVideoAd *rewardBasedVideoAd = [[GADURewardBasedVideoAd alloc]
  226. initWithRewardBasedVideoClientReference:rewardBasedVideoAdClient];
  227. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  228. cache[rewardBasedVideoAd.gadu_referenceKey] = rewardBasedVideoAd;
  229. return (__bridge GADUTypeRewardBasedVideoAdRef)rewardBasedVideoAd;
  230. }
  231. /// Creates a GADURewardedAd and returns its reference.
  232. GADUTypeRewardedAdRef GADUCreateRewardedAd(GADUTypeRewardedAdClientRef *rewardedAdClient,
  233. const char *adUnitID) {
  234. GADURewardedAd *rewardedAd =
  235. [[GADURewardedAd alloc] initWithRewardedAdClientReference:rewardedAdClient
  236. adUnitID:GADUStringFromUTF8String(adUnitID)];
  237. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  238. cache[rewardedAd.gadu_referenceKey] = rewardedAd;
  239. return (__bridge GADUTypeRewardedAdRef)rewardedAd;
  240. }
  241. /// Creates a GADURewardedInterstitialAd and returns its reference.
  242. GADUTypeRewardedInterstitialAdRef GADUCreateRewardedInterstitialAd(
  243. GADUTypeRewardedInterstitialAdClientRef *rewardedInterstitialAdClient) {
  244. GADURewardedInterstitialAd *rewardedInterstitialAd = [[GADURewardedInterstitialAd alloc]
  245. initWithRewardedInterstitialAdClientReference:rewardedInterstitialAdClient];
  246. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  247. cache[rewardedInterstitialAd.gadu_referenceKey] = rewardedInterstitialAd;
  248. return (__bridge GADUTypeRewardedInterstitialAdRef)rewardedInterstitialAd;
  249. }
  250. /// Creates a GADUAdLoader and returns its reference.
  251. GADUTypeAdLoaderRef GADUCreateAdLoader(GADUTypeAdLoaderClientRef *adLoaderClient,
  252. const char *adUnitID,
  253. const char **templateIDs, NSInteger templateIDLength,
  254. struct AdTypes *types, BOOL returnUrlsForImageAssets) {
  255. NSMutableArray *templateIDsArray = [[NSMutableArray alloc] init];
  256. for (int i = 0; i < templateIDLength; i++) {
  257. [templateIDsArray addObject:GADUStringFromUTF8String(templateIDs[i])];
  258. }
  259. NSMutableArray *adTypesArray = [[NSMutableArray alloc] init];
  260. if (types->CustomTemplateAd) {
  261. [adTypesArray addObject:kGADAdLoaderAdTypeNativeCustomTemplate];
  262. }
  263. NSMutableArray *options = nil;
  264. GADUAdLoader *adLoader =
  265. [[GADUAdLoader alloc] initWithAdLoaderClientReference:adLoaderClient
  266. adUnitID:GADUStringFromUTF8String(adUnitID)
  267. templateIDs:templateIDsArray
  268. adTypes:adTypesArray
  269. options:options];
  270. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  271. cache[adLoader.gadu_referenceKey] = adLoader;
  272. return (__bridge GADUTypeAdLoaderRef)adLoader;
  273. }
  274. /// Sets the banner callback methods to be invoked during banner ad events.
  275. void GADUSetBannerCallbacks(GADUTypeBannerRef banner,
  276. GADUAdViewDidReceiveAdCallback adReceivedCallback,
  277. GADUAdViewDidFailToReceiveAdWithErrorCallback adFailedCallback,
  278. GADUAdViewWillPresentScreenCallback willPresentCallback,
  279. GADUAdViewDidDismissScreenCallback didDismissCallback,
  280. GADUAdViewWillLeaveApplicationCallback willLeaveCallback,
  281. GADUAdViewPaidEventCallback paidEventCallback) {
  282. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  283. internalBanner.adReceivedCallback = adReceivedCallback;
  284. internalBanner.adFailedCallback = adFailedCallback;
  285. internalBanner.willPresentCallback = willPresentCallback;
  286. internalBanner.didDismissCallback = didDismissCallback;
  287. internalBanner.willLeaveCallback = willLeaveCallback;
  288. internalBanner.paidEventCallback = paidEventCallback;
  289. }
  290. /// Sets the interstitial callback methods to be invoked during interstitial ad events.
  291. void GADUSetInterstitialCallbacks(
  292. GADUTypeInterstitialRef interstitial, GADUInterstitialDidReceiveAdCallback adReceivedCallback,
  293. GADUInterstitialDidFailToReceiveAdWithErrorCallback adFailedCallback,
  294. GADUInterstitialWillPresentScreenCallback willPresentCallback,
  295. GADUInterstitialDidDismissScreenCallback didDismissCallback,
  296. GADUInterstitialWillLeaveApplicationCallback willLeaveCallback,
  297. GADUInterstitialPaidEventCallback paidEventCallback) {
  298. GADUInterstitial *internalInterstitial = (__bridge GADUInterstitial *)interstitial;
  299. internalInterstitial.adReceivedCallback = adReceivedCallback;
  300. internalInterstitial.adFailedCallback = adFailedCallback;
  301. internalInterstitial.willPresentCallback = willPresentCallback;
  302. internalInterstitial.didDismissCallback = didDismissCallback;
  303. internalInterstitial.willLeaveCallback = willLeaveCallback;
  304. internalInterstitial.paidEventCallback = paidEventCallback;
  305. }
  306. /// Sets the reward based video callback methods to be invoked during reward based video ad events.
  307. void GADUSetRewardBasedVideoAdCallbacks(
  308. GADUTypeRewardBasedVideoAdRef rewardBasedVideoAd,
  309. GADURewardBasedVideoAdDidReceiveAdCallback adReceivedCallback,
  310. GADURewardBasedVideoAdDidFailToReceiveAdWithErrorCallback adFailedCallback,
  311. GADURewardBasedVideoAdDidOpenCallback didOpenCallback,
  312. GADURewardBasedVideoAdDidStartPlayingCallback didStartCallback,
  313. GADURewardBasedVideoAdDidCloseCallback didCloseCallback,
  314. GADURewardBasedVideoAdDidRewardCallback didRewardCallback,
  315. GADURewardBasedVideoAdWillLeaveApplicationCallback willLeaveCallback,
  316. GADURewardBasedVideoAdDidCompleteCallback didCompleteCallback) {
  317. GADURewardBasedVideoAd *internalRewardBasedVideoAd =
  318. (__bridge GADURewardBasedVideoAd *)rewardBasedVideoAd;
  319. internalRewardBasedVideoAd.adReceivedCallback = adReceivedCallback;
  320. internalRewardBasedVideoAd.adFailedCallback = adFailedCallback;
  321. internalRewardBasedVideoAd.didOpenCallback = didOpenCallback;
  322. internalRewardBasedVideoAd.didStartPlayingCallback = didStartCallback;
  323. internalRewardBasedVideoAd.didCloseCallback = didCloseCallback;
  324. internalRewardBasedVideoAd.didRewardCallback = didRewardCallback;
  325. internalRewardBasedVideoAd.willLeaveCallback = willLeaveCallback;
  326. internalRewardBasedVideoAd.didCompleteCallback = didCompleteCallback;
  327. }
  328. /// Sets the rewarded ad callback methods to be invoked during reward based video ad events.
  329. void GADUSetRewardedAdCallbacks(
  330. GADUTypeRewardedAdRef rewardedAd, GADURewardedAdDidReceiveAdCallback adReceivedCallback,
  331. GADURewardedAdDidFailToReceiveAdWithErrorCallback adFailedToLoadCallback,
  332. GADURewardedAdDidFailToShowAdWithErrorCallback adFailedToShowCallback,
  333. GADURewardedAdDidOpenCallback didOpenCallback, GADURewardedAdDidCloseCallback didCloseCallback,
  334. GADUUserEarnedRewardCallback didEarnRewardCallback,
  335. GADURewardedAdPaidEventCallback paidEventCallback) {
  336. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  337. internalRewardedAd.adReceivedCallback = adReceivedCallback;
  338. internalRewardedAd.adFailedToLoadCallback = adFailedToLoadCallback;
  339. internalRewardedAd.adFailedToShowCallback = adFailedToShowCallback;
  340. internalRewardedAd.didOpenCallback = didOpenCallback;
  341. internalRewardedAd.didCloseCallback = didCloseCallback;
  342. internalRewardedAd.didEarnRewardCallback = didEarnRewardCallback;
  343. internalRewardedAd.paidEventCallback = paidEventCallback;
  344. }
  345. /// Sets the rewarded interstitial ad callback methods to be invoked during rewarded interstitial ad
  346. /// events.
  347. void GADUSetRewardedInterstitialAdCallbacks(
  348. GADUTypeRewardedInterstitialAdRef rewardedInterstitialAd,
  349. GADURewardedInterstitialAdLoadedCallback adLoadedCallback,
  350. GADURewardedInterstitialAdFailedToLoadCallback adFailedToLoadCallback,
  351. GADUUserEarnedRewardCallback didEarnRewardCallback,
  352. GADURewardedInterstitialAdPaidEventCallback paidEventCallback,
  353. GADUFailedToPresentFullScreenContentCallback adFailToPresentFullScreenContentCallback,
  354. GADUDidPresentFullScreenContentCallback adDidPresentFullScreenContentCallback,
  355. GADUDidDismissFullScreenContentCallback adDidDismissFullScreenContentCallback) {
  356. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  357. (__bridge GADURewardedInterstitialAd *)rewardedInterstitialAd;
  358. internalRewardedInterstitialAd.adLoadedCallback = adLoadedCallback;
  359. internalRewardedInterstitialAd.adFailedToLoadCallback = adFailedToLoadCallback;
  360. internalRewardedInterstitialAd.didEarnRewardCallback = didEarnRewardCallback;
  361. internalRewardedInterstitialAd.paidEventCallback = paidEventCallback;
  362. internalRewardedInterstitialAd.adFailedToPresentFullScreenContentCallback =
  363. adFailToPresentFullScreenContentCallback;
  364. internalRewardedInterstitialAd.adDidPresentFullScreenContentCallback =
  365. adDidPresentFullScreenContentCallback;
  366. internalRewardedInterstitialAd.adDidDismissFullScreenContentCallback =
  367. adDidDismissFullScreenContentCallback;
  368. }
  369. /// Sets the banner callback methods to be invoked during native ad events.
  370. void GADUSetAdLoaderCallbacks(
  371. GADUTypeAdLoaderRef adLoader,
  372. GADUAdLoaderDidReceiveNativeCustomTemplateAdCallback customTemplateAdReceivedCallback,
  373. GADUAdLoaderDidFailToReceiveAdWithErrorCallback adFailedCallback) {
  374. GADUAdLoader *internalAdLoader = (__bridge GADUAdLoader *)adLoader;
  375. internalAdLoader.customTemplateAdReceivedCallback = customTemplateAdReceivedCallback;
  376. internalAdLoader.adFailedCallback = adFailedCallback;
  377. }
  378. /// Sets the GADBannerView's hidden property to YES.
  379. void GADUHideBannerView(GADUTypeBannerRef banner) {
  380. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  381. [internalBanner hideBannerView];
  382. }
  383. /// Sets the GADBannerView's hidden property to NO.
  384. void GADUShowBannerView(GADUTypeBannerRef banner) {
  385. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  386. [internalBanner showBannerView];
  387. }
  388. /// Removes the GADURemoveBannerView from the view hierarchy.
  389. void GADURemoveBannerView(GADUTypeBannerRef banner) {
  390. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  391. [internalBanner removeBannerView];
  392. }
  393. float GADUGetBannerViewHeightInPixels(GADUTypeBannerRef banner) {
  394. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  395. return internalBanner.heightInPixels;
  396. }
  397. float GADUGetBannerViewWidthInPixels(GADUTypeBannerRef banner) {
  398. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  399. return internalBanner.widthInPixels;
  400. }
  401. /// Returns YES if the GADInterstitial is ready to be shown.
  402. BOOL GADUInterstitialReady(GADUTypeInterstitialRef interstitial) {
  403. GADUInterstitial *internalInterstitial = (__bridge GADUInterstitial *)interstitial;
  404. return [internalInterstitial isReady];
  405. }
  406. /// Shows the GADInterstitial.
  407. void GADUShowInterstitial(GADUTypeInterstitialRef interstitial) {
  408. GADUInterstitial *internalInterstitial = (__bridge GADUInterstitial *)interstitial;
  409. [internalInterstitial show];
  410. }
  411. /// Returns YES if the GADRewardBasedVideo is ready to be shown.
  412. BOOL GADURewardBasedVideoAdReady(GADUTypeRewardBasedVideoAdRef rewardBasedVideo) {
  413. GADURewardBasedVideoAd *internalRewardBasedVideoAd =
  414. (__bridge GADURewardBasedVideoAd *)rewardBasedVideo;
  415. return [internalRewardBasedVideoAd isReady];
  416. }
  417. /// Sets the user ID to be used in server-to-server reward callbacks.
  418. void GADUSetRewardBasedVideoAdUserId(GADUTypeRewardBasedVideoAdRef rewardBasedVideo,
  419. const char *userId) {
  420. GADURewardBasedVideoAd *internalRewardBasedVideoAd =
  421. (__bridge GADURewardBasedVideoAd *)rewardBasedVideo;
  422. [internalRewardBasedVideoAd setUserId:GADUStringFromUTF8String(userId)];
  423. }
  424. /// Shows the GADRewardBasedVideo.
  425. void GADUShowRewardBasedVideoAd(GADUTypeRewardBasedVideoAdRef rewardBasedVideoAd) {
  426. GADURewardBasedVideoAd *internalRewardBasedVideoAd =
  427. (__bridge GADURewardBasedVideoAd *)rewardBasedVideoAd;
  428. [internalRewardBasedVideoAd show];
  429. }
  430. /// Returns YES if the GADRewardedAd is ready to be shown.
  431. BOOL GADURewardedAdReady(GADUTypeRewardedAdRef rewardedAd) {
  432. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  433. return [internalRewardedAd isReady];
  434. }
  435. /// Shows the GADRewardedAd.
  436. void GADUShowRewardedAd(GADUTypeRewardedAdRef rewardedAd) {
  437. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  438. [internalRewardedAd show];
  439. }
  440. /// Returns the type of the reward.
  441. const char *GADURewardedAdGetRewardType(GADUTypeRewardedAdRef rewardedAd) {
  442. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  443. GADAdReward *reward = internalRewardedAd.rewardedAd.reward;
  444. return cStringCopy(reward.type.UTF8String);
  445. }
  446. /// Returns the amount of the reward.
  447. double GADURewardedAdGetRewardAmount(GADUTypeRewardedAdRef rewardedAd) {
  448. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  449. GADAdReward *reward = internalRewardedAd.rewardedAd.reward;
  450. return reward.amount.doubleValue;
  451. }
  452. /// Shows the GADRewardedInterstitialAd.
  453. void GADUShowRewardedInterstitialAd(GADUTypeRewardedInterstitialAdRef rewardedInterstitialAd) {
  454. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  455. (__bridge GADURewardedInterstitialAd *)rewardedInterstitialAd;
  456. [internalRewardedInterstitialAd show];
  457. }
  458. /// Returns the type of the reward.
  459. const char *GADURewardedInterstitialAdGetRewardType(
  460. GADUTypeRewardedInterstitialAdRef rewardedInterstitialAd) {
  461. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  462. (__bridge GADURewardedInterstitialAd *)rewardedInterstitialAd;
  463. GADAdReward *reward = internalRewardedInterstitialAd.rewardedInterstitialAd.adReward;
  464. return cStringCopy(reward.type.UTF8String);
  465. }
  466. /// Returns the amount of the reward.
  467. double GADURewardedInterstitialAdGetRewardAmount(
  468. GADUTypeRewardedInterstitialAdRef rewardedInterstitialAd) {
  469. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  470. (__bridge GADURewardedInterstitialAd *)rewardedInterstitialAd;
  471. GADAdReward *reward = internalRewardedInterstitialAd.rewardedInterstitialAd.adReward;
  472. return reward.amount.doubleValue;
  473. }
  474. /// Create an empty CreateRequestConfiguration
  475. GADUTypeRequestConfigurationRef GADUCreateRequestConfiguration() {
  476. GADURequestConfiguration *requestConfiguration = [[GADURequestConfiguration alloc] init];
  477. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  478. cache[requestConfiguration.gadu_referenceKey] = requestConfiguration;
  479. return (__bridge GADUTypeRequestConfigurationRef)(requestConfiguration);
  480. }
  481. /// Set MobileAds RequestConfiguration
  482. void GADUSetRequestConfiguration(GADUTypeRequestConfigurationRef requestConfiguration) {
  483. GADURequestConfiguration *internalRequestConfiguration =
  484. (__bridge GADURequestConfiguration *)requestConfiguration;
  485. GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating =
  486. internalRequestConfiguration.maxAdContentRating;
  487. GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers =
  488. internalRequestConfiguration.testDeviceIdentifiers;
  489. switch (internalRequestConfiguration.tagForUnderAgeOfConsent) {
  490. case (kGADURequestConfigurationTagForUnderAgeOfConsentTrue): {
  491. [GADMobileAds.sharedInstance.requestConfiguration tagForUnderAgeOfConsent:true];
  492. break;
  493. }
  494. case (kGADURequestConfigurationTagForUnderAgeOfConsentFalse): {
  495. [GADMobileAds.sharedInstance.requestConfiguration tagForUnderAgeOfConsent:false];
  496. break;
  497. }
  498. case (kGADURequestConfigurationTagForUnderAgeOfConsentUnspecified): {
  499. break;
  500. }
  501. }
  502. switch (internalRequestConfiguration.tagForChildDirectedTreatment) {
  503. case (kGADURequestConfigurationTagForChildDirectedTreatmentTrue): {
  504. [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment:true];
  505. break;
  506. }
  507. case (kGADURequestConfigurationTagForChildDirectedTreatmentFalse): {
  508. [GADMobileAds.sharedInstance.requestConfiguration tagForChildDirectedTreatment:false];
  509. break;
  510. }
  511. case (kGADURequestConfigurationTagForChildDirectedTreatmentUnspecified): {
  512. break;
  513. }
  514. }
  515. }
  516. /// Set RequestConfiguration Max Ad Content Rating
  517. void GADUSetRequestConfigurationMaxAdContentRating(
  518. GADUTypeRequestConfigurationRef requestConfiguration, const char *maxAdContentRating) {
  519. GADURequestConfiguration *internalRequestConfiguration =
  520. (__bridge GADURequestConfiguration *)requestConfiguration;
  521. [internalRequestConfiguration setMaxAdContentRating:GADUStringFromUTF8String(maxAdContentRating)];
  522. }
  523. /// Set RequestConfiguration Test Device Ids
  524. void GADUSetRequestConfigurationTestDeviceIdentifiers(
  525. GADUTypeRequestConfigurationRef requestConfiguration, const char **testDeviceIDs,
  526. NSInteger testDeviceIDLength) {
  527. GADURequestConfiguration *internalRequestConfiguration =
  528. (__bridge GADURequestConfiguration *)requestConfiguration;
  529. NSMutableArray *testDeviceIDsArray = [[NSMutableArray alloc] init];
  530. for (int i = 0; i < testDeviceIDLength; i++) {
  531. [testDeviceIDsArray addObject:GADUStringFromUTF8String(testDeviceIDs[i])];
  532. }
  533. [internalRequestConfiguration setTestDeviceIdentifiers:testDeviceIDsArray];
  534. }
  535. /// Set RequestConfiguration tagForUnderAgeOfConsent
  536. void GADUSetRequestConfigurationTagForUnderAgeOfConsent(
  537. GADUTypeRequestConfigurationRef requestConfiguration, int tagForUnderAgeOfConsent) {
  538. GADURequestConfiguration *internalRequestConfiguration =
  539. (__bridge GADURequestConfiguration *)requestConfiguration;
  540. internalRequestConfiguration.tagForUnderAgeOfConsent = tagForUnderAgeOfConsent;
  541. }
  542. /// Set RequestConfiguration tagForChildDirectedTreatment
  543. void GADUSetRequestConfigurationTagForChildDirectedTreatment(
  544. GADUTypeRequestConfigurationRef requestConfiguration, int tagForChildDirectedTreatment) {
  545. GADURequestConfiguration *internalRequestConfiguration =
  546. (__bridge GADURequestConfiguration *)requestConfiguration;
  547. internalRequestConfiguration.tagForChildDirectedTreatment = tagForChildDirectedTreatment;
  548. }
  549. /// Returns RequestConfiguration Max Ad Content Rating
  550. const char *GADUGetMaxAdContentRating(GADUTypeRequestConfigurationRef requestConfiguration) {
  551. GADURequestConfiguration *internalRequestConfiguration =
  552. (__bridge GADURequestConfiguration *)requestConfiguration;
  553. return cStringCopy(internalRequestConfiguration.maxAdContentRating.UTF8String);
  554. }
  555. /// Returns RequestConfiguration tag For Under Age Of Consent
  556. const int GADUGetRequestConfigurationTagForUnderAgeOfConsent(
  557. GADUTypeRequestConfigurationRef requestConfiguration) {
  558. GADURequestConfiguration *internalRequestConfiguration =
  559. (__bridge GADURequestConfiguration *)requestConfiguration;
  560. return internalRequestConfiguration.tagForUnderAgeOfConsent;
  561. }
  562. /// Returns RequestConfiguration tag For Child Directed Treatment
  563. const int GADUGetRequestConfigurationTagForChildDirectedTreatment(
  564. GADUTypeRequestConfigurationRef requestConfiguration) {
  565. GADURequestConfiguration *internalRequestConfiguration =
  566. (__bridge GADURequestConfiguration *)requestConfiguration;
  567. return internalRequestConfiguration.tagForChildDirectedTreatment;
  568. }
  569. /// Returns List RequestConfiguration Test Device Ids
  570. const char **GADUGetTestDeviceIdentifiers(GADUTypeRequestConfigurationRef requestConfiguration) {
  571. GADURequestConfiguration *internalRequestConfiguration =
  572. (__bridge GADURequestConfiguration *)requestConfiguration;
  573. NSArray<NSString *> *testDeviceIDs = internalRequestConfiguration.testDeviceIdentifiers;
  574. return cStringArrayCopy(testDeviceIDs);
  575. }
  576. /// Returns count of RequestConfiguration Test Device Ids
  577. int GADUGetTestDeviceIdentifiersCount(GADUTypeRequestConfigurationRef requestConfiguration) {
  578. GADURequestConfiguration *internalRequestConfiguration =
  579. (__bridge GADURequestConfiguration *)requestConfiguration;
  580. NSArray<NSString *> *testDeviceIDs = internalRequestConfiguration.testDeviceIdentifiers;
  581. return testDeviceIDs.count;
  582. }
  583. /// Creates an empty GADRequest and returns its reference.
  584. GADUTypeRequestRef GADUCreateRequest() {
  585. GADURequest *request = [[GADURequest alloc] init];
  586. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  587. cache[request.gadu_referenceKey] = request;
  588. return (__bridge GADUTypeRequestRef)(request);
  589. }
  590. /// Adds a test device to the GADRequest.
  591. void GADUAddTestDevice(GADUTypeRequestRef request, const char *deviceID) {
  592. GADURequest *internalRequest = (__bridge GADURequest *)request;
  593. [internalRequest addTestDevice:GADUStringFromUTF8String(deviceID)];
  594. }
  595. /// Adds a keyword to the GADRequest.
  596. void GADUAddKeyword(GADUTypeRequestRef request, const char *keyword) {
  597. GADURequest *internalRequest = (__bridge GADURequest *)request;
  598. [internalRequest addKeyword:GADUStringFromUTF8String(keyword)];
  599. }
  600. /// Sets the request agent for the GADRequest.
  601. void GADUSetRequestAgent(GADUTypeRequestRef request, const char *requestAgent) {
  602. GADURequest *internalRequest = (__bridge GADURequest *)request;
  603. [internalRequest setRequestAgent:GADUStringFromUTF8String(requestAgent)];
  604. }
  605. /// Sets the user's birthday on the GADRequest.
  606. void GADUSetBirthday(GADUTypeRequestRef request, NSInteger year, NSInteger month, NSInteger day) {
  607. GADURequest *internalRequest = (__bridge GADURequest *)request;
  608. [internalRequest setBirthdayWithMonth:month day:day year:year];
  609. }
  610. /// Sets the user's gender on the GADRequest.
  611. void GADUSetGender(GADUTypeRequestRef request, NSInteger genderCode) {
  612. GADURequest *internalRequest = (__bridge GADURequest *)request;
  613. [internalRequest setGenderWithCode:genderCode];
  614. }
  615. /// Tags a GADRequest to specify whether it should be treated as child-directed for purposes of the
  616. /// Children’s Online Privacy Protection Act (COPPA) -
  617. /// http://business.ftc.gov/privacy-and-security/childrens-privacy.
  618. void GADUTagForChildDirectedTreatment(GADUTypeRequestRef request, BOOL childDirectedTreatment) {
  619. GADURequest *internalRequest = (__bridge GADURequest *)request;
  620. internalRequest.tagForChildDirectedTreatment = childDirectedTreatment;
  621. }
  622. /// Creates an empty GADServerSideVerificationOptions and returns its reference.
  623. GADUTypeServerSideVerificationOptionsRef GADUCreateServerSideVerificationOptions() {
  624. GADServerSideVerificationOptions *options = [[GADServerSideVerificationOptions alloc] init];
  625. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  626. cache[options.gadu_referenceKey] = options;
  627. return (__bridge GADUTypeServerSideVerificationOptionsRef)(options);
  628. }
  629. /// Sets the user id on the GADServerSideVerificationOptions
  630. void GADUServerSideVerificationOptionsSetUserId(GADUTypeServerSideVerificationOptionsRef options,
  631. const char *userId) {
  632. GADServerSideVerificationOptions *internalOptions =
  633. (__bridge GADServerSideVerificationOptions *)options;
  634. internalOptions.userIdentifier = GADUStringFromUTF8String(userId);
  635. }
  636. /// Sets the custom reward string on the GADServerSideVerificationOptions
  637. void GADUServerSideVerificationOptionsSetCustomRewardString(
  638. GADUTypeServerSideVerificationOptionsRef options, const char *customRewardString) {
  639. GADServerSideVerificationOptions *internalOptions =
  640. (__bridge GADServerSideVerificationOptions *)options;
  641. internalOptions.customRewardString = GADUStringFromUTF8String(customRewardString);
  642. }
  643. /// Creates an empty NSMutableableDictionary returns its reference.
  644. GADUTypeMutableDictionaryRef GADUCreateMutableDictionary() {
  645. NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
  646. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  647. cache[dictionary.gadu_referenceKey] = dictionary;
  648. return (__bridge GADUTypeMutableDictionaryRef)(dictionary);
  649. }
  650. /// Sets an mediation extra key value pair on a NSMutableableDictionary.
  651. void GADUMutableDictionarySetValue(GADUTypeMutableDictionaryRef dictionary, const char *key,
  652. const char *value) {
  653. NSMutableDictionary *internalDictionary = (__bridge NSMutableDictionary *)dictionary;
  654. [internalDictionary setValue:GADUStringFromUTF8String(value)
  655. forKey:GADUStringFromUTF8String(key)];
  656. }
  657. /// Create a GADMediatonExtras object from the specified NSMutableableDictionary of extras and
  658. /// include it in the ad request.
  659. void GADUSetMediationExtras(GADUTypeRequestRef request, GADUTypeMutableDictionaryRef dictionary,
  660. const char *adNetworkExtraClassName) {
  661. GADURequest *internalRequest = (__bridge GADURequest *)request;
  662. NSMutableDictionary *internalDictionary = (__bridge NSMutableDictionary *)dictionary;
  663. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  664. id<GADUAdNetworkExtras> extra =
  665. [[NSClassFromString(GADUStringFromUTF8String(adNetworkExtraClassName)) alloc] init];
  666. if (![extra respondsToSelector:@selector(adNetworkExtrasWithDictionary:)]) {
  667. NSLog(@"Unable to create mediation ad network class: %@",
  668. GADUStringFromUTF8String(adNetworkExtraClassName));
  669. [cache removeObjectForKey:[internalDictionary gadu_referenceKey]];
  670. return;
  671. }
  672. [internalRequest.mediationExtras
  673. addObject:[extra adNetworkExtrasWithDictionary:internalDictionary]];
  674. [cache removeObjectForKey:[internalDictionary gadu_referenceKey]];
  675. }
  676. /// Sets an extra parameter to be included in the ad request.
  677. void GADUSetExtra(GADUTypeRequestRef request, const char *key, const char *value) {
  678. GADURequest *internalRequest = (__bridge GADURequest *)request;
  679. [internalRequest setExtraWithKey:GADUStringFromUTF8String(key)
  680. value:GADUStringFromUTF8String(value)];
  681. }
  682. /// Makes a banner ad request.
  683. void GADURequestBannerAd(GADUTypeBannerRef banner, GADUTypeRequestRef request) {
  684. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  685. GADURequest *internalRequest = (__bridge GADURequest *)request;
  686. [internalBanner loadRequest:[internalRequest request]];
  687. }
  688. void GADUSetBannerViewAdPosition(GADUTypeBannerRef banner, int position) {
  689. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  690. [internalBanner setAdPosition:(GADAdPosition)position];
  691. }
  692. void GADUSetBannerViewCustomPosition(GADUTypeBannerRef banner, int x, int y) {
  693. GADUBanner *internalBanner = (__bridge GADUBanner *)banner;
  694. [internalBanner setCustomAdPosition:CGPointMake(x, y)];
  695. }
  696. /// Makes an interstitial ad request.
  697. void GADURequestInterstitial(GADUTypeInterstitialRef interstitial, GADUTypeRequestRef request) {
  698. GADUInterstitial *internalInterstitial = (__bridge GADUInterstitial *)interstitial;
  699. GADURequest *internalRequest = (__bridge GADURequest *)request;
  700. [internalInterstitial loadRequest:[internalRequest request]];
  701. }
  702. /// Makes a rewarded video ad request.
  703. void GADURequestRewardBasedVideoAd(GADUTypeRewardBasedVideoAdRef rewardBasedVideoAd,
  704. GADUTypeRequestRef request, const char *adUnitID) {
  705. GADURewardBasedVideoAd *internalRewardBasedVideoAd =
  706. (__bridge GADURewardBasedVideoAd *)rewardBasedVideoAd;
  707. GADURequest *internalRequest = (__bridge GADURequest *)request;
  708. [internalRewardBasedVideoAd loadRequest:[internalRequest request]
  709. withAdUnitID:GADUStringFromUTF8String(adUnitID)];
  710. }
  711. /// Makes a rewarded ad request.
  712. void GADURequestRewardedAd(GADUTypeRewardedAdRef rewardedAd, GADUTypeRequestRef request) {
  713. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  714. GADURequest *internalRequest = (__bridge GADURequest *)request;
  715. [internalRewardedAd loadRequest:[internalRequest request]];
  716. }
  717. /// Makes a rewarded interstitial ad request.
  718. void GADULoadRewardedInterstitialAd(GADUTypeRewardedInterstitialAdRef rewardedInterstitialAd,
  719. const char *adUnitID, GADUTypeRequestRef request) {
  720. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  721. (__bridge GADURewardedInterstitialAd *)rewardedInterstitialAd;
  722. GADURequest *internalRequest = (__bridge GADURequest *)request;
  723. [internalRewardedInterstitialAd loadWithAdUnitID:GADUStringFromUTF8String(adUnitID)
  724. request:[internalRequest request]];
  725. }
  726. /// Makes a native ad request.
  727. void GADURequestNativeAd(GADUTypeAdLoaderRef adLoader, GADUTypeRequestRef request) {
  728. GADUAdLoader *internalAdLoader = (__bridge GADUAdLoader *)adLoader;
  729. GADURequest *internalRequest = (__bridge GADURequest *)request;
  730. [internalAdLoader loadRequest:[internalRequest request]];
  731. }
  732. /// Sets the GADServerSideVerificationOptions on GADURewardedAd
  733. void GADURewardedAdSetServerSideVerificationOptions(
  734. GADUTypeRewardedAdRef rewardedAd, GADUTypeServerSideVerificationOptionsRef options) {
  735. GADURewardedAd *internalRewardedAd = (__bridge GADURewardedAd *)rewardedAd;
  736. GADServerSideVerificationOptions *internalOptions =
  737. (__bridge GADServerSideVerificationOptions *)options;
  738. [internalRewardedAd setServerSideVerificationOptions:internalOptions];
  739. }
  740. /// Sets the GADServerSideVerificationOptions on GADURewardedInterstitialAd
  741. void GADURewardedInterstitialAdSetServerSideVerificationOptions(
  742. GADUTypeRewardedInterstitialAdRef rewardedInterstitialAd,
  743. GADUTypeServerSideVerificationOptionsRef options) {
  744. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  745. (__bridge GADURewardedInterstitialAd *)rewardedInterstitialAd;
  746. GADServerSideVerificationOptions *internalOptions =
  747. (__bridge GADServerSideVerificationOptions *)options;
  748. [internalRewardedInterstitialAd setServerSideVerificationOptions:internalOptions];
  749. }
  750. #pragma mark - Native Custom Template Ad methods
  751. /// Return the template ID of the native custom template ad.
  752. const char *GADUNativeCustomTemplateAdTemplateID(
  753. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd) {
  754. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  755. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  756. return cStringCopy([internalNativeCustomTemplateAd templateID].UTF8String);
  757. }
  758. /// Returns the image corresponding to the specifed key as a base64 encoded byte array.
  759. const char *GADUNativeCustomTemplateAdImageAsBytesForKey(
  760. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd, const char *key) {
  761. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  762. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  763. NSData *imageData = UIImageJPEGRepresentation(
  764. [internalNativeCustomTemplateAd imageForKey:GADUStringFromUTF8String(key)], 0.0);
  765. NSString *base64String = [imageData base64EncodedStringWithOptions:0];
  766. return cStringCopy(base64String.UTF8String);
  767. }
  768. /// Returns the string corresponding to the specifed key.
  769. const char *GADUNativeCustomTemplateAdStringForKey(
  770. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd, const char *key) {
  771. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  772. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  773. return cStringCopy(
  774. [internalNativeCustomTemplateAd stringForKey:GADUStringFromUTF8String(key)].UTF8String);
  775. }
  776. /// Call when the ad is played on screen to the user.
  777. void GADUNativeCustomTemplateAdRecordImpression(
  778. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd) {
  779. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  780. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  781. [internalNativeCustomTemplateAd recordImpression];
  782. }
  783. /// Call when the user clicks on an ad.
  784. void GADUNativeCustomTemplateAdPerformClickOnAssetWithKey(
  785. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd, const char *key,
  786. BOOL customClickAction) {
  787. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  788. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  789. [internalNativeCustomTemplateAd performClickOnAssetWithKey:GADUStringFromUTF8String(key)
  790. withCustomClickAction:customClickAction];
  791. }
  792. /// Returns the list of available asset keys for a custom native template ad.
  793. const char **GADUNativeCustomTemplateAdAvailableAssetKeys(
  794. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd) {
  795. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  796. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  797. NSArray *availableAssetKeys = [internalNativeCustomTemplateAd availableAssetKeys];
  798. return cStringArrayCopy(availableAssetKeys);
  799. }
  800. /// Returns the number of available asset keys for a custom native template ad.
  801. int GADUNativeCustomTemplateAdNumberOfAvailableAssetKeys(
  802. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd) {
  803. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  804. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  805. return (int)[internalNativeCustomTemplateAd availableAssetKeys].count;
  806. }
  807. /// Sets the Unity native custom template ad client reference on GADUNativeCustomTemplateAd.
  808. void GADUSetNativeCustomTemplateAdUnityClient(
  809. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd,
  810. GADUTypeNativeCustomTemplateAdClientRef *nativeCustomTemplateClient) {
  811. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  812. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  813. internalNativeCustomTemplateAd.nativeCustomTemplateClient = nativeCustomTemplateClient;
  814. }
  815. /// Sets the ad callback methods to be invoked during native custom template ad events.
  816. void GADUSetNativeCustomTemplateAdCallbacks(
  817. GADUTypeNativeCustomTemplateAdRef nativeCustomTemplateAd,
  818. GADUNativeCustomTemplateDidReceiveClickCallback adClickedCallback) {
  819. GADUNativeCustomTemplateAd *internalNativeCustomTemplateAd =
  820. (__bridge GADUNativeCustomTemplateAd *)nativeCustomTemplateAd;
  821. internalNativeCustomTemplateAd.didReceiveClickCallback = adClickedCallback;
  822. }
  823. const GADUTypeResponseInfoRef GADUGetResponseInfo(GADUTypeRef adFormat) {
  824. id internalAd = (__bridge id)adFormat;
  825. GADResponseInfo *responseInfo;
  826. if ([internalAd isKindOfClass:[GADUBanner class]]){
  827. GADUBanner *internalBanner = (GADUBanner *)internalAd;
  828. responseInfo = internalBanner.responseInfo;
  829. } else if ([internalAd isKindOfClass:[GADUInterstitial class]]) {
  830. GADUInterstitial *internalInterstitial = (GADUInterstitial *)internalAd;
  831. responseInfo = internalInterstitial.responseInfo;
  832. } else if ([internalAd isKindOfClass:[GADURewardedAd class]]){
  833. GADURewardedAd *internalRewardedAd = (GADURewardedAd *)internalAd;
  834. responseInfo = internalRewardedAd.responseInfo;
  835. } else if ([internalAd isKindOfClass:[GADURewardedInterstitialAd class]]) {
  836. GADURewardedInterstitialAd *internalRewardedInterstitialAd =
  837. (GADURewardedInterstitialAd *)internalAd;
  838. responseInfo = internalRewardedInterstitialAd.responseInfo;
  839. }
  840. if (responseInfo){
  841. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  842. cache[responseInfo.gadu_referenceKey] = responseInfo;
  843. return (__bridge GADUTypeResponseInfoRef)(responseInfo);
  844. }else {
  845. return nil;
  846. }
  847. }
  848. const char *GADUResponseInfoMediationAdapterClassName(GADUTypeResponseInfoRef responseInfo){
  849. GADResponseInfo *internalResponseInfo = (__bridge GADResponseInfo *)responseInfo;
  850. return cStringCopy(internalResponseInfo.adNetworkClassName.UTF8String);
  851. }
  852. const char *GADUResponseInfoResponseId(GADUTypeResponseInfoRef responseInfo){
  853. GADResponseInfo *internalResponseInfo = (__bridge GADResponseInfo *)responseInfo;
  854. return cStringCopy(internalResponseInfo.responseIdentifier.UTF8String);
  855. }
  856. const char *GADUGetResponseInfoDescription(GADUTypeResponseInfoRef responseInfo){
  857. GADResponseInfo *internalResponseInfo = (__bridge GADResponseInfo *)responseInfo;
  858. return cStringCopy(internalResponseInfo.description.UTF8String);
  859. }
  860. #pragma mark - Other methods
  861. /// Removes an object from the cache.
  862. void GADURelease(GADUTypeRef ref) {
  863. if (ref) {
  864. GADUObjectCache *cache = [GADUObjectCache sharedInstance];
  865. [cache removeObjectForKey:[(__bridge NSObject *)ref gadu_referenceKey]];
  866. }
  867. }
  868. const char *GADUMediationAdapterClassNameForBannerView(GADUTypeBannerRef bannerView) {
  869. GADUBanner *banner = (__bridge GADUBanner *)bannerView;
  870. return cStringCopy(banner.mediationAdapterClassName.UTF8String);
  871. }
  872. const char *GADUMediationAdapterClassNameForRewardedVideo(
  873. GADUTypeRewardBasedVideoAdRef rewardedVideo) {
  874. GADURewardBasedVideoAd *rewarded = (__bridge GADURewardBasedVideoAd *)rewardedVideo;
  875. return cStringCopy(rewarded.mediationAdapterClassName.UTF8String);
  876. }
  877. const char *GADUMediationAdapterClassNameForRewardedAd(GADUTypeRewardedAdRef rewardedAd) {
  878. GADURewardedAd *rewarded = (__bridge GADURewardedAd *)rewardedAd;
  879. return cStringCopy(rewarded.mediationAdapterClassName.UTF8String);
  880. }
  881. const char *GADUMediationAdapterClassNameForInterstitial(GADUTypeInterstitialRef interstitial) {
  882. GADUInterstitial *interstitialAd = (__bridge GADUInterstitial *)interstitial;
  883. return cStringCopy(interstitialAd.mediationAdapterClassName.UTF8String);
  884. }