iOSAgent.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. #if UNITY_IPHONE || UNITY_IOS
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. using System.Linq;
  7. using System;
  8. public class iOSAgent : IronSourceIAgent
  9. {
  10. [DllImport("__Internal")]
  11. private static extern void CFReportAppStarted ();
  12. [DllImport("__Internal")]
  13. private static extern void CFSetPluginData (string pluginType, string pluginVersion, string pluginFrameworkVersion);
  14. [DllImport("__Internal")]
  15. private static extern void CFSetAge (int age);
  16. [DllImport("__Internal")]
  17. private static extern void CFSetGender (string gender);
  18. [DllImport("__Internal")]
  19. private static extern void CFSetMediationSegment (string segment);
  20. [DllImport("__Internal")]
  21. private static extern string CFGetAdvertiserId ();
  22. [DllImport("__Internal")]
  23. private static extern void CFValidateIntegration ();
  24. [DllImport("__Internal")]
  25. private static extern void CFShouldTrackNetworkState (bool track);
  26. [DllImport("__Internal")]
  27. private static extern bool CFSetDynamicUserId (string dynamicUserId);
  28. [DllImport("__Internal")]
  29. private static extern void CFSetAdaptersDebug (bool enabled);
  30. //******************* SDK Init *******************//
  31. [DllImport("__Internal")]
  32. private static extern void CFSetUserId (string userId);
  33. [DllImport("__Internal")]
  34. private static extern void CFInit (string appKey);
  35. [DllImport("__Internal")]
  36. private static extern void CFInitWithAdUnits (string appKey, params string[] adUnits);
  37. [DllImport("__Internal")]
  38. private static extern void CFInitISDemandOnly (string appKey, params string[] adUnits);
  39. //******************* RewardedVideo API *******************//
  40. [DllImport("__Internal")]
  41. private static extern void CFShowRewardedVideo ();
  42. [DllImport("__Internal")]
  43. private static extern void CFShowRewardedVideoWithPlacementName (string placementName);
  44. [DllImport("__Internal")]
  45. private static extern bool CFIsRewardedVideoAvailable ();
  46. [DllImport("__Internal")]
  47. private static extern bool CFIsRewardedVideoPlacementCapped (string placementName);
  48. [DllImport("__Internal")]
  49. private static extern string CFGetPlacementInfo (string placementName);
  50. [DllImport("__Internal")]
  51. private static extern void CFSetRewardedVideoServerParameters (string jsonString);
  52. [DllImport("__Internal")]
  53. private static extern void CFClearRewardedVideoServerParameters ();
  54. //******************* RewardedVideo DemandOnly API *******************//
  55. [DllImport("__Internal")]
  56. private static extern void CFShowISDemandOnlyRewardedVideo (string instanceId);
  57. [DllImport("__Internal")]
  58. private static extern void CFShowISDemandOnlyRewardedVideoWithPlacementName (string instanceId, string placementName);
  59. [DllImport("__Internal")]
  60. private static extern bool CFIsDemandOnlyRewardedVideoAvailable (string instanceId);
  61. //******************* Interstitial API *******************//
  62. [DllImport("__Internal")]
  63. private static extern void CFLoadInterstitial ();
  64. [DllImport("__Internal")]
  65. private static extern void CFShowInterstitial ();
  66. [DllImport("__Internal")]
  67. private static extern void CFShowInterstitialWithPlacementName (string placementName);
  68. [DllImport("__Internal")]
  69. private static extern bool CFIsInterstitialReady ();
  70. [DllImport("__Internal")]
  71. private static extern bool CFIsInterstitialPlacementCapped (string placementName);
  72. //******************* Interstitial DemandOnly API *******************//
  73. [DllImport("__Internal")]
  74. private static extern void CFLoadISDemandOnlyInterstitial (string instanceId);
  75. [DllImport("__Internal")]
  76. private static extern void CFShowISDemandOnlyInterstitial(string instanceId);
  77. [DllImport("__Internal")]
  78. private static extern void CFShowISDemandOnlyInterstitialWithPlacementName (string instanceId, string placementName);
  79. [DllImport("__Internal")]
  80. private static extern bool CFIsDemandOnlyInterstitialReady (string instanceId);
  81. //******************* Offerwall API *******************//
  82. [DllImport("__Internal")]
  83. private static extern void CFShowOfferwall ();
  84. [DllImport("__Internal")]
  85. private static extern void CFShowOfferwallWithPlacementName (string placementName);
  86. [DllImport("__Internal")]
  87. private static extern void CFGetOfferwallCredits ();
  88. [DllImport("__Internal")]
  89. private static extern bool CFIsOfferwallAvailable ();
  90. //******************* Banner API *******************//
  91. [DllImport("__Internal")]
  92. private static extern void CFLoadBanner (int size, int position);
  93. [DllImport("__Internal")]
  94. private static extern void CFLoadBannerWithPlacementName (int size, int position, string placementName);
  95. [DllImport("__Internal")]
  96. private static extern void CFDestroyBanner ();
  97. [DllImport("__Internal")]
  98. private static extern void CFDisplayBanner ();
  99. [DllImport("__Internal")]
  100. private static extern void CFHideBanner ();
  101. [DllImport("__Internal")]
  102. private static extern bool CFIsBannerPlacementCapped (string placementName);
  103. [DllImport("__Internal")]
  104. private static extern void CFSetSegment(string json);
  105. [DllImport("__Internal")]
  106. private static extern void CFSetConsent(bool consent);
  107. public iOSAgent ()
  108. {
  109. }
  110. #region IronSourceIAgent implementation
  111. public void reportAppStarted ()
  112. {
  113. CFReportAppStarted ();
  114. }
  115. //******************* Base API *******************//
  116. public void onApplicationPause (bool pause)
  117. {
  118. }
  119. public void setAge (int age)
  120. {
  121. CFSetAge (age);
  122. }
  123. public void setGender (string gender)
  124. {
  125. CFSetGender (gender);
  126. }
  127. public void setMediationSegment (string segment)
  128. {
  129. CFSetMediationSegment (segment);
  130. }
  131. public string getAdvertiserId ()
  132. {
  133. return CFGetAdvertiserId ();
  134. }
  135. public void validateIntegration ()
  136. {
  137. CFValidateIntegration ();
  138. }
  139. public void shouldTrackNetworkState (bool track)
  140. {
  141. CFShouldTrackNetworkState (track);
  142. }
  143. public bool setDynamicUserId (string dynamicUserId)
  144. {
  145. return CFSetDynamicUserId (dynamicUserId);
  146. }
  147. public void setAdaptersDebug(bool enabled)
  148. {
  149. CFSetAdaptersDebug (enabled);
  150. }
  151. //******************* SDK Init *******************//
  152. public void setUserId (string userId)
  153. {
  154. CFSetUserId (userId);
  155. }
  156. public void init (string appKey)
  157. {
  158. CFSetPluginData ("Unity", IronSource.pluginVersion(), IronSource.unityVersion());
  159. CFInit (appKey);
  160. }
  161. public void init (string appKey, params string[] adUnits)
  162. {
  163. CFSetPluginData ("Unity", IronSource.pluginVersion(), IronSource.unityVersion());
  164. CFInitWithAdUnits (appKey, adUnits);
  165. }
  166. public void initISDemandOnly (string appKey, params string[] adUnits)
  167. {
  168. CFSetPluginData ("Unity", IronSource.pluginVersion(), IronSource.unityVersion());
  169. CFInitISDemandOnly (appKey, adUnits);
  170. }
  171. //******************* RewardedVideo API *******************//
  172. public void showRewardedVideo ()
  173. {
  174. CFShowRewardedVideo ();
  175. }
  176. public void showRewardedVideo (string placementName)
  177. {
  178. CFShowRewardedVideoWithPlacementName (placementName);
  179. }
  180. public bool isRewardedVideoAvailable ()
  181. {
  182. return CFIsRewardedVideoAvailable ();
  183. }
  184. public bool isRewardedVideoPlacementCapped (string placementName)
  185. {
  186. return CFIsRewardedVideoPlacementCapped (placementName);
  187. }
  188. public IronSourcePlacement getPlacementInfo (string placementName)
  189. {
  190. IronSourcePlacement sp = null;
  191. string spString = CFGetPlacementInfo (placementName);
  192. if (spString != null) {
  193. Dictionary<string,object> spDic = IronSourceJSON.Json.Deserialize (spString) as Dictionary<string,object>;
  194. string pName = spDic ["placement_name"].ToString ();
  195. string rewardName = spDic ["reward_name"].ToString ();
  196. int rewardAmount = Convert.ToInt32 (spDic ["reward_amount"].ToString ());
  197. sp = new IronSourcePlacement (pName, rewardName, rewardAmount);
  198. }
  199. return sp;
  200. }
  201. public void setRewardedVideoServerParams(Dictionary<string, string> parameters){
  202. string json = IronSourceJSON.Json.Serialize (parameters);
  203. CFSetRewardedVideoServerParameters (json);
  204. }
  205. public void clearRewardedVideoServerParams(){
  206. CFClearRewardedVideoServerParameters ();
  207. }
  208. //******************* RewardedVideo DemandOnly API *******************//
  209. public void showISDemandOnlyRewardedVideo (string instanceId)
  210. {
  211. CFShowISDemandOnlyRewardedVideo(instanceId);
  212. }
  213. public void showISDemandOnlyRewardedVideo (string instanceId, string placementName)
  214. {
  215. CFShowISDemandOnlyRewardedVideoWithPlacementName(instanceId, placementName);
  216. }
  217. public bool isISDemandOnlyRewardedVideoAvailable (string instanceId)
  218. {
  219. return CFIsDemandOnlyRewardedVideoAvailable(instanceId);
  220. }
  221. //******************* Interstitial API *******************//
  222. public void loadInterstitial ()
  223. {
  224. CFLoadInterstitial ();
  225. }
  226. public void showInterstitial ()
  227. {
  228. CFShowInterstitial ();
  229. }
  230. public void showInterstitial (string placementName)
  231. {
  232. CFShowInterstitialWithPlacementName (placementName);
  233. }
  234. public bool isInterstitialReady ()
  235. {
  236. return CFIsInterstitialReady ();
  237. }
  238. public bool isInterstitialPlacementCapped (string placementName)
  239. {
  240. return CFIsInterstitialPlacementCapped (placementName);
  241. }
  242. //******************* Interstitial DemandOnly API *******************//
  243. public void loadISDemandOnlyInterstitial (string instanceId)
  244. {
  245. CFLoadISDemandOnlyInterstitial (instanceId);
  246. }
  247. public void showISDemandOnlyInterstitial (string instanceId)
  248. {
  249. CFShowISDemandOnlyInterstitial(instanceId);
  250. }
  251. public void showISDemandOnlyInterstitial (string instanceId, string placementName)
  252. {
  253. CFShowISDemandOnlyInterstitialWithPlacementName (instanceId, placementName);
  254. }
  255. public bool isISDemandOnlyInterstitialReady (string instanceId)
  256. {
  257. return CFIsDemandOnlyInterstitialReady (instanceId);
  258. }
  259. //******************* Offerwall API *******************//
  260. public void showOfferwall ()
  261. {
  262. CFShowOfferwall ();
  263. }
  264. public void showOfferwall (string placementName)
  265. {
  266. CFShowOfferwallWithPlacementName (placementName);
  267. }
  268. public void getOfferwallCredits ()
  269. {
  270. CFGetOfferwallCredits ();
  271. }
  272. public bool isOfferwallAvailable ()
  273. {
  274. return CFIsOfferwallAvailable ();
  275. }
  276. //******************* Banner API *******************//
  277. public void loadBanner (IronSourceBannerSize size, IronSourceBannerPosition position)
  278. {
  279. CFLoadBanner ((int)size, (int)position);
  280. }
  281. public void loadBanner (IronSourceBannerSize size, IronSourceBannerPosition position, string placementName)
  282. {
  283. CFLoadBannerWithPlacementName ((int)size, (int)position, placementName);
  284. }
  285. public void destroyBanner ()
  286. {
  287. CFDestroyBanner ();
  288. }
  289. public void displayBanner ()
  290. {
  291. CFDisplayBanner ();
  292. }
  293. public void hideBanner ()
  294. {
  295. CFHideBanner ();
  296. }
  297. public bool isBannerPlacementCapped (string placementName)
  298. {
  299. return CFIsBannerPlacementCapped (placementName);
  300. }
  301. public void setSegment(IronSourceSegment segment){
  302. Dictionary <string,string> dict = segment.getSegmentAsDict ();
  303. string json = IronSourceJSON.Json.Serialize (dict);
  304. CFSetSegment (json);
  305. }
  306. public void setConsent(bool consent)
  307. {
  308. CFSetConsent(consent);
  309. }
  310. #endregion
  311. }
  312. #endif