ATJSSDK.ts 5.5 KB

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