You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

95 lines
3.1 KiB

  1. // Copyright (C) 2015 Google, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if UNITY_IOS
  15. using System;
  16. using System.Collections.Generic;
  17. using GoogleMobileAds.Api;
  18. using GoogleMobileAds.Api.Mediation;
  19. using GoogleMobileAds.Common;
  20. namespace GoogleMobileAds.iOS
  21. {
  22. internal class Utils
  23. {
  24. // Creates an ad request.
  25. public static IntPtr BuildAdRequest(AdRequest request)
  26. {
  27. IntPtr requestPtr = Externs.GADUCreateRequest();
  28. foreach (string keyword in request.Keywords)
  29. {
  30. Externs.GADUAddKeyword(requestPtr, keyword);
  31. }
  32. foreach (string deviceId in request.TestDevices)
  33. {
  34. Externs.GADUAddTestDevice(requestPtr, deviceId);
  35. }
  36. if (request.Birthday.HasValue)
  37. {
  38. DateTime birthday = request.Birthday.GetValueOrDefault();
  39. Externs.GADUSetBirthday(requestPtr, birthday.Year, birthday.Month, birthday.Day);
  40. }
  41. if (request.Gender.HasValue)
  42. {
  43. Externs.GADUSetGender(requestPtr, (int)request.Gender.GetValueOrDefault());
  44. }
  45. if (request.TagForChildDirectedTreatment.HasValue)
  46. {
  47. Externs.GADUTagForChildDirectedTreatment(
  48. requestPtr,
  49. request.TagForChildDirectedTreatment.GetValueOrDefault());
  50. }
  51. foreach (KeyValuePair<string, string> entry in request.Extras)
  52. {
  53. Externs.GADUSetExtra(requestPtr, entry.Key, entry.Value);
  54. }
  55. Externs.GADUSetExtra(requestPtr, "is_unity", "1");
  56. foreach (MediationExtras mediationExtra in request.MediationExtras)
  57. {
  58. IntPtr mutableDictionaryPtr = Externs.GADUCreateMutableDictionary();
  59. if (mutableDictionaryPtr != IntPtr.Zero)
  60. {
  61. foreach (KeyValuePair<string, string> entry in mediationExtra.Extras)
  62. {
  63. Externs.GADUMutableDictionarySetValue(
  64. mutableDictionaryPtr,
  65. entry.Key,
  66. entry.Value);
  67. }
  68. Externs.GADUSetMediationExtras(
  69. requestPtr,
  70. mutableDictionaryPtr,
  71. mediationExtra.IOSMediationExtraBuilderClassName);
  72. }
  73. }
  74. Externs.GADUSetRequestAgent(requestPtr, "unity-" + AdRequest.Version);
  75. return requestPtr;
  76. }
  77. }
  78. }
  79. #endif