ATJSSDK.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import {ATAndroidJS} from "./Android/ATAndroidJS"
  2. import {ATiOSJS} from "./iOS/ATiOSJS";
  3. import { _decorator, Component, Node, sys ,log } from 'cc';
  4. const { ccclass, property } = _decorator;
  5. var isDebugLog = false;
  6. var initPlatformBridge = function() {
  7. if (sys.os === sys.OS.IOS) {
  8. return ATiOSJS;
  9. } else if (sys.os === sys.OS.ANDROID) {
  10. return ATAndroidJS;
  11. }
  12. };
  13. var platformBridge = initPlatformBridge();
  14. export const ATJSSDK = {
  15. kATUserLocationUnknown : 0,
  16. kATUserLocationInEU : 1,
  17. kATUserLocationOutOfEU : 2,
  18. PERSONALIZED : 0,
  19. NONPERSONALIZED :1,
  20. UNKNOWN : 2,
  21. //for android and ios
  22. OS_VERSION_NAME : "os_vn",
  23. OS_VERSION_CODE : "os_vc",
  24. APP_PACKAGE_NAME : "package_name",
  25. APP_VERSION_NAME : "app_vn",
  26. APP_VERSION_CODE : "app_vc",
  27. BRAND : "brand",
  28. MODEL : "model",
  29. DEVICE_SCREEN_SIZE : "screen",
  30. MNC : "mnc",
  31. MCC : "mcc",
  32. LANGUAGE : "language",
  33. TIMEZONE : "timezone",
  34. USER_AGENT : "ua",
  35. ORIENTATION : "orient",
  36. NETWORK_TYPE : "network_type",
  37. //for android
  38. INSTALLER : "it_src",
  39. ANDROID_ID : "android_id",
  40. GAID : "gaid",
  41. MAC : "mac",
  42. IMEI : "imei",
  43. OAID : "oaid",
  44. //for ios
  45. IDFA : "idfa",
  46. IDFV : "idfv",
  47. ATSDKListener : {
  48. userLocationCallback : null,
  49. getUserLocationCallback : function(userLocation) {
  50. if(undefined != this.userLocationCallback && this.userLocationCallback != null ){
  51. this.userLocationCallback(userLocation);
  52. }
  53. }
  54. },
  55. initSDK : function(appId, appKey) {
  56. if (undefined != platformBridge && platformBridge != null) {
  57. platformBridge.initSDK(appId, appKey);
  58. } else {
  59. log("You must run on Android or iOS.");
  60. }
  61. },
  62. initCustomMap : function(customMap) {
  63. if (undefined != platformBridge && platformBridge != null) {
  64. if(undefined != customMap && customMap != null) {
  65. platformBridge.initCustomMap(JSON.stringify(customMap));
  66. }
  67. } else {
  68. log("You must run on Android or iOS.");
  69. }
  70. },
  71. setPlacementCustomMap : function(placmentId, customMap) {
  72. if (undefined != platformBridge && platformBridge != null) {
  73. if(undefined != customMap && customMap != null) {
  74. platformBridge.setPlacementCustomMap(placmentId, JSON.stringify(customMap));
  75. }
  76. } else {
  77. log("You must run on Android or iOS.");
  78. }
  79. },
  80. setGDPRLevel : function(level) {
  81. if (undefined != platformBridge && platformBridge != null) {
  82. platformBridge.setGDPRLevel(level);
  83. } else {
  84. log("You must run on Android or iOS.");
  85. }
  86. },
  87. getGDPRLevel : function() {
  88. if (undefined != platformBridge && platformBridge != null) {
  89. return platformBridge.getGDPRLevel();
  90. } else {
  91. log("You must run on Android or iOS.");
  92. }
  93. return this.UNKNOWN;
  94. },
  95. getUserLocation : function(userLocationCallback) {
  96. this.ATSDKListener.userLocationCallback = userLocationCallback;
  97. if (undefined != platformBridge && platformBridge != null) {
  98. platformBridge.getUserLocation(GetUserLocationJsCallback);
  99. } else {
  100. log("You must run on Android or iOS.");
  101. }
  102. },
  103. showGDPRAuth : function () {
  104. if (undefined != platformBridge && platformBridge != null) {
  105. platformBridge.showGDPRAuth();
  106. } else {
  107. log("You must run on Android or iOS.");
  108. }
  109. },
  110. setLogDebug : function (debug) {
  111. isDebugLog = debug;
  112. if (undefined != platformBridge && platformBridge != null) {
  113. platformBridge.setLogDebug(debug);
  114. } else {
  115. log("You must run on Android or iOS.");
  116. }
  117. },
  118. printLog : function(msg) {
  119. if (undefined != msg && null != msg && isDebugLog && platformBridge != null ) {
  120. if (undefined != platformBridge && platformBridge != null) {
  121. platformBridge.printJsLog(msg);
  122. } else {
  123. log("You must run on Android or iOS.");
  124. }
  125. }
  126. },
  127. printLogWithParams : function(tag, methodName, placementId, callbackInfo, errorInfo) {
  128. this.printLog(tag + "::" + methodName + "()" + "\nplacementId=" + placementId + "\ncallbackInfo=" + callbackInfo + "\nerrorInfo=" + errorInfo);
  129. },
  130. deniedUploadDeviceInfo : function (deniedInfo) {
  131. if (undefined != platformBridge && platformBridge != null) {
  132. if (deniedInfo != null) {
  133. var length = deniedInfo.length;
  134. var deniedInfoString = "";
  135. for (var i = 0; i < length; i++) {
  136. var info = deniedInfo[i];
  137. if (i == 0) {
  138. deniedInfoString = info;
  139. } else {
  140. deniedInfoString = deniedInfoString + "," + info;
  141. }
  142. }
  143. log("test__" + deniedInfoString)
  144. platformBridge.deniedUploadDeviceInfo(deniedInfoString);
  145. }
  146. } else {
  147. log("You must run on Android or iOS.");
  148. }
  149. },
  150. showDebuggerUI : function (debugKey) {
  151. if (undefined != platformBridge && platformBridge != null) {
  152. platformBridge.showDebuggerUI(debugKey);
  153. }
  154. }
  155. };
  156. const GetUserLocationJsCallback = " ATJSSDK.ATSDKListener.getUserLocationCallback";
  157. const VersionCode = 'v1.1.0';
  158. window["ATJSSDK"] = ATJSSDK;
  159. export default ATJSSDK;