com.amanotes.gdk 0.2.48 → 0.2.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/Editor/AmaGDKEditor.cs +149 -63
  3. package/Editor/AmaGDKExtra.cs +31 -0
  4. package/Editor/AmaGDKExtra.cs.meta +11 -0
  5. package/Editor/Extra/GDKAutoBuild.cs +891 -0
  6. package/Editor/Extra/GDKAutoBuild.cs.meta +3 -0
  7. package/Editor/Extra/GDKProjectCP.cs +158 -0
  8. package/Editor/Extra/GDKProjectCP.cs.meta +11 -0
  9. package/Editor/Extra.meta +8 -0
  10. package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +1 -1
  11. package/Extra/AmaGDKInstaller.unitypackage +0 -0
  12. package/Extra/AndroidPostProcessor.unitypackage +0 -0
  13. package/Extra/{AmaGDKProject.unitypackage.meta → AndroidPostProcessor.unitypackage.meta} +1 -1
  14. package/Extra/CheckDiskSpace.unitypackage +0 -0
  15. package/Extra/CheckDiskSpace.unitypackage.meta +7 -0
  16. package/Extra/SDKVersionTracking.unitypackage +0 -0
  17. package/Extra/SDKVersionTracking.unitypackage.meta +7 -0
  18. package/Packages/AmaGDKConfig.unitypackage +0 -0
  19. package/Packages/AmaGDKExample.unitypackage +0 -0
  20. package/Packages/AmaGDKTest.unitypackage +0 -0
  21. package/Packages/AppsFlyerAdapter.unitypackage +0 -0
  22. package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
  23. package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
  24. package/Packages/IronSourceAdapter.unitypackage +0 -0
  25. package/Packages/RevenueCatAdapter.unitypackage +0 -0
  26. package/Runtime/AmaGDK.Adapters.cs +0 -4
  27. package/Runtime/AmaGDK.Ads.cs +92 -31
  28. package/Runtime/AmaGDK.Analytics.cs +97 -64
  29. package/Runtime/AmaGDK.IAP.cs +39 -45
  30. package/Runtime/AmaGDK.RemoteConfig.cs +76 -52
  31. package/Runtime/AmaGDK.UserProfile.cs +106 -124
  32. package/Runtime/AmaGDK.cs +46 -35
  33. package/Runtime/Internal/AmaGDK.Event.cs +185 -0
  34. package/Runtime/Internal/AmaGDK.Event.cs.meta +3 -0
  35. package/Runtime/Internal/AmaGDK.Internal.cs +4 -0
  36. package/Runtime/Internal/AmaGDK.Utils.cs +85 -24
  37. package/Runtime/Klavar/Attributes.meta +0 -4
  38. package/Runtime/Klavar.meta +0 -4
  39. package/package.json +1 -1
  40. package/Extra/AmaGDKProject.unitypackage +0 -0
@@ -17,17 +17,22 @@ namespace Amanotes.Core
17
17
  {
18
18
  public enum RemoteConfigSource
19
19
  {
20
- EmbedConfig,
20
+ None,
21
21
  Cache,
22
+ Local,
22
23
  Internet
23
24
  }
24
25
 
26
+ partial class Event
27
+ {
28
+ public const string REMOTE_CONFIG_FETCH_COMPLETE = nameof(REMOTE_CONFIG_FETCH_COMPLETE);
29
+ }
30
+
25
31
  [Serializable]
26
32
  public partial class RemoteConfig //Public
27
33
  {
28
- public static Action<bool> onFetchCompleted;
29
- public static Dictionary<string, string> DictConfig => dictConfig;
30
- public static RemoteConfigSource Source { private set; get; }
34
+ public static RemoteConfigSource Source { private set; get; } = RemoteConfigSource.None;
35
+
31
36
  static bool? _cacheExisted = null;
32
37
  public static bool HasCache
33
38
  {
@@ -73,8 +78,8 @@ namespace Amanotes.Core
73
78
  return (T)Convert.ChangeType(c.value, typeof(T));
74
79
  }
75
80
  #endif
76
- if (dictConfig.ContainsKey(key))
77
- return (T)Convert.ChangeType(dictConfig[key], typeof(T));
81
+ if (DictConfig.ContainsKey(key))
82
+ return (T)Convert.ChangeType(DictConfig[key], typeof(T));
78
83
  return defaultValue;
79
84
  }
80
85
 
@@ -85,7 +90,7 @@ namespace Amanotes.Core
85
90
 
86
91
  public static string GetConfigAsJsonString()
87
92
  {
88
- return JsonUtils.DictionaryToJson(dictConfig);
93
+ return JsonUtils.DictionaryToJson(DictConfig);
89
94
  }
90
95
 
91
96
  public static void SetActiveEmbedConfig(string id)
@@ -105,7 +110,6 @@ namespace Amanotes.Core
105
110
  internal enum FetchState
106
111
  {
107
112
  None,
108
- CheckInternet,
109
113
  Fetch,
110
114
  SaveCache,
111
115
 
@@ -116,7 +120,9 @@ namespace Amanotes.Core
116
120
  Fail
117
121
  }
118
122
 
119
- static Dictionary<string, string> dictConfig = new Dictionary<string, string>();
123
+ public static Dictionary<string, string> DictConfig { get; private set; } = new Dictionary<string, string>();
124
+
125
+
120
126
  static string fileName = $"{nameof(RemoteConfig)}.kv";
121
127
  static string base64Prefix = "base64:";
122
128
  const string VERSION_PREFIX = "version:";
@@ -125,28 +131,25 @@ namespace Amanotes.Core
125
131
  ? Config.remoteConfig.embedRemoteConfig.version
126
132
  : 1;
127
133
 
128
- static FetchState _state = FetchState.None;
129
- internal static FetchState State => _state;
134
+ static FetchState _fetchState = FetchState.None;
135
+ internal static FetchState fetchState => _fetchState;
130
136
 
131
137
  static readonly Dictionary<FetchState, Action[]> fetchSM = new Dictionary<FetchState, Action[]>
132
138
  {
133
- { FetchState.None, new Action[]{ CheckInternet}},
134
- { FetchState.CheckInternet, new Action[]{ LoadCache, Fetch}},
139
+ { FetchState.None, new Action[]{ Fetch}},
135
140
  { FetchState.Fetch, new Action[]{ LoadCache, SaveCache}},
136
141
  { FetchState.SaveCache, new Action[]{ SetDone }},
137
142
  { FetchState.LoadCache, new Action[]{ LoadEmbedConfig, SetDone}},
138
- { FetchState.LoadEmbedConfig, new Action[]{ SetFail, SetDone}}
143
+ { FetchState.LoadEmbedConfig, new Action[]{ SetFail, SetDone}}
139
144
  };
140
145
 
141
146
  internal static RemoteConfigAdapter adapter;
142
-
143
- internal static Action<bool> onAdapterInitCompleteCallback;
144
147
 
145
148
  internal static void NextState(bool result = true)
146
149
  {
147
- if (!fetchSM.TryGetValue(_state, out var actions))
150
+ if (!fetchSM.TryGetValue(_fetchState, out var actions))
148
151
  {
149
- LogWarning("[RemoteConfig] Invalid / Unsupported state: " + _state);
152
+ LogWarning("[RemoteConfig] Invalid / Unsupported state: " + _fetchState);
150
153
  return;
151
154
  }
152
155
 
@@ -159,15 +162,37 @@ namespace Amanotes.Core
159
162
  actions[result ? 1 : 0]();
160
163
  }
161
164
 
162
- static void CheckInternet()
165
+ internal static void InitModule()
163
166
  {
164
- _state = FetchState.CheckInternet;
165
- NextState(Application.internetReachability != NetworkReachability.NotReachable);
167
+ adapter = Adapter2.GetAdapter<RemoteConfigAdapter>();
168
+ }
169
+
170
+ internal static void StartModule()
171
+ {
172
+ if (adapter != null) Fetch();
173
+ }
174
+
175
+ public static void SetFetchCompleteCallback(Action<RemoteConfigSource> callback)
176
+ {
177
+
178
+ if (_fetchState == FetchState.Success || _fetchState == FetchState.Fail)
179
+ {
180
+ callback?.Invoke(Source);
181
+ return;
182
+ }
183
+
184
+ dispatcher.AddListener(Event.REMOTE_CONFIG_FETCH_COMPLETE, callback, true);
166
185
  }
167
186
 
168
187
  static void Fetch()
169
188
  {
170
- _state = FetchState.Fetch;
189
+ if (adapter == null)
190
+ {
191
+ _fetchState = FetchState.None;
192
+ return;
193
+ }
194
+
195
+ _fetchState = FetchState.Fetch;
171
196
  adapter.FetchConfig(HasCache, (isSuccess, result) =>
172
197
  {
173
198
  if (!isSuccess)
@@ -175,8 +200,8 @@ namespace Amanotes.Core
175
200
  NextState(false);
176
201
  return;
177
202
  }
178
-
179
- dictConfig = result;
203
+
204
+ DictConfig = result;
180
205
  Source = RemoteConfigSource.Internet;
181
206
  Log("[RemoteConfig] Load from the internet");
182
207
  NextState(true);
@@ -187,13 +212,13 @@ namespace Amanotes.Core
187
212
  {
188
213
  Profiler.BeginSample("AmaGDK.RemoteConfig.SaveCache()");
189
214
 
190
- _state = FetchState.SaveCache;
215
+ _fetchState = FetchState.SaveCache;
191
216
  StringBuilder sb = new StringBuilder();
192
217
 
193
218
  //Add embedded remote config version to force load from embedded config after app update
194
219
  sb.AppendLine($"{VERSION_PREFIX}{EmbedVersion}");
195
220
 
196
- foreach (var c in dictConfig)
221
+ foreach (var c in DictConfig)
197
222
  {
198
223
  sb.AppendLine($"{c.Key}\t{Encode(c.Value)}");
199
224
  }
@@ -209,7 +234,7 @@ namespace Amanotes.Core
209
234
  {
210
235
  Profiler.BeginSample("AmaGDK.RemoteConfig.LoadCache()");
211
236
 
212
- _state = FetchState.LoadCache;
237
+ _fetchState = FetchState.LoadCache;
213
238
 
214
239
  if (!HasCache)
215
240
  {
@@ -220,7 +245,7 @@ namespace Amanotes.Core
220
245
 
221
246
  try
222
247
  {
223
- dictConfig.Clear();
248
+ DictConfig.Clear();
224
249
  using (StreamReader sr = new StreamReader(GDKFileUtils.GetPath(fileName)))
225
250
  {
226
251
  //Check new app update
@@ -253,10 +278,10 @@ namespace Amanotes.Core
253
278
  }
254
279
  string key = line.Substring(0, idx);
255
280
  string value = line.Substring(idx + 1);
256
- dictConfig.Add(key, Decode(value));
281
+ DictConfig.Add(key, Decode(value));
257
282
  }
258
283
  }
259
- Source = RemoteConfigSource.Cache;
284
+ Source = RemoteConfigSource.Local;
260
285
  Log("[RemoteConfig] Load from cache");
261
286
  }
262
287
  catch (Exception ex)
@@ -274,7 +299,7 @@ namespace Amanotes.Core
274
299
 
275
300
  static void LoadEmbedConfig()
276
301
  {
277
- _state = FetchState.LoadEmbedConfig;
302
+ _fetchState = FetchState.LoadEmbedConfig;
278
303
 
279
304
  if (_config.remoteConfig == null || _config.remoteConfig.embedRemoteConfig == null)
280
305
  {
@@ -292,25 +317,24 @@ namespace Amanotes.Core
292
317
 
293
318
  foreach (var item in config.items)
294
319
  {
295
- dictConfig.Add(item.key, item.value);
320
+ DictConfig.Add(item.key, item.value);
296
321
  }
297
- Source = RemoteConfigSource.EmbedConfig;
322
+ Source = RemoteConfigSource.Cache;
298
323
  Log("[RemoteConfig] Load from embed asset");
299
324
  NextState(true);
300
325
  }
301
326
 
302
327
  static void SetDone()
303
328
  {
304
- _state = FetchState.Success;
305
- onAdapterInitCompleteCallback(true);
306
- onFetchCompleted?.Invoke(true);
329
+ _fetchState = FetchState.Success;
330
+ dispatcher.Dispatch(Event.REMOTE_CONFIG_FETCH_COMPLETE, Source);
307
331
  }
308
332
 
309
333
  static void SetFail()
310
334
  {
311
- _state = FetchState.Fail;
312
- onAdapterInitCompleteCallback(false);
313
- onFetchCompleted?.Invoke(false);
335
+ _fetchState = FetchState.Fail;
336
+ Source = RemoteConfigSource.None;
337
+ dispatcher.Dispatch(Event.REMOTE_CONFIG_FETCH_COMPLETE, Source);
314
338
  }
315
339
 
316
340
  static string Encode(string s)
@@ -338,19 +362,19 @@ namespace Amanotes.Core
338
362
  }
339
363
  }
340
364
 
341
- public static class RemoteConfigExtension
342
- {
343
- public static void InitRemoteConfigModule(this RemoteConfigAdapter ap, Action<bool> onCompleteCallback)
344
- {
345
- if (AmaGDK.RemoteConfig.State != AmaGDK.RemoteConfig.FetchState.None)
346
- {
347
- LogWarning($"[RemoteConfig] Current state {AmaGDK.RemoteConfig.State.ToString()}\nCannot start to initialize");
348
- return;
349
- }
350
- AmaGDK.RemoteConfig.onAdapterInitCompleteCallback = onCompleteCallback;
351
- AmaGDK.RemoteConfig.NextState();
352
- }
353
- }
365
+ // public static class RemoteConfigExtension
366
+ // {
367
+ // public static void InitRemoteConfigModule(this RemoteConfigAdapter ap, Action<bool> onCompleteCallback)
368
+ // {
369
+ // if (AmaGDK.RemoteConfig.fetchState != AmaGDK.RemoteConfig.FetchState.None)
370
+ // {
371
+ // LogWarning($"[RemoteConfig] Current state {AmaGDK.RemoteConfig.fetchState.ToString()}\nCannot start to initialize");
372
+ // return;
373
+ // }
374
+ //
375
+ // AmaGDK.RemoteConfig.NextState();
376
+ // }
377
+ // }
354
378
  }
355
379
 
356
380
  namespace Amanotes.Core.Internal
@@ -1,36 +1,40 @@
1
1
  using System;
2
- using System.Collections;
3
2
  using System.Text.RegularExpressions;
4
3
  using Amanotes.Core.Internal;
4
+ using System.Collections.Generic;
5
5
  using UnityEngine;
6
+
6
7
  namespace Amanotes.Core
7
8
  {
8
9
  public partial class AmaGDK //User profile
9
10
  {
10
11
  public static readonly UserProfile User = new UserProfile();
11
- public static event Action<string> OnUserIdChanged;
12
12
 
13
13
  [Serializable]
14
14
  public partial class UserProfile : IJsonFile
15
15
  {
16
- private const string FILE_NAME = nameof(UserProfile);
17
- [NonSerialized] internal bool _dirty;
18
-
19
16
  private void Save()
20
17
  {
21
- GDKFileUtils.Save(FILE_NAME, JsonUtility.ToJson(this));
22
- }
23
-
24
- internal void SaveIfDirty()
25
- {
26
- if (!_dirty) return;
27
- _dirty = false;
28
18
  this.SaveJsonToFile();
29
19
  }
30
20
  }
31
21
 
32
22
  public partial class UserProfile //PUBLIC
33
23
  {
24
+ public Dictionary<string, object> CollectAllUserIds()
25
+ {
26
+ var dic = new Dictionary<string, object>();
27
+ if (!string.IsNullOrWhiteSpace(IDFA)) dic["idfa"] = IDFA;
28
+ if (!string.IsNullOrWhiteSpace(IDFV)) dic["idfv"] = IDFV;
29
+ if (!string.IsNullOrWhiteSpace(GAId)) dic["gaid"] = GAId;
30
+ if (!string.IsNullOrWhiteSpace(AndroidId)) dic["android_id"] = AndroidId;
31
+ if (!string.IsNullOrWhiteSpace(PseudoId)) dic["pseudo_id"] = PseudoId;
32
+ if (!string.IsNullOrWhiteSpace(AmaDeviceId)) dic["ama_device_id"] = AmaDeviceId;
33
+ if (!string.IsNullOrWhiteSpace(AppsFlyerId)) dic["appsflyer_id"] = AppsFlyerId;
34
+ if (!string.IsNullOrWhiteSpace(InstallationId)) dic["installation_id"] = InstallationId;
35
+ return dic;
36
+ }
37
+
34
38
  public string UserId
35
39
  {
36
40
  get
@@ -40,9 +44,8 @@ namespace Amanotes.Core
40
44
  }
41
45
  private set
42
46
  {
43
- if (_userId == value) return;
47
+ if (_userId == value) return;
44
48
  _userId = value;
45
- OnUserIdChanged?.Invoke(_userId);
46
49
  Save();
47
50
  }
48
51
  }
@@ -102,65 +105,8 @@ namespace Amanotes.Core
102
105
  get => _installationId;
103
106
  set => _installationId = ValidateId(value, ALPHANUMERIC_PATTERN);
104
107
  }
105
- }
106
-
107
- public partial class UserProfile //INTERNAL
108
- {
109
- [SerializeField]
110
- private string _userId;
111
- [SerializeField]
112
- private string _gaid;
113
- [SerializeField]
114
- private string _idfa;
115
- [SerializeField]
116
- private string _idfv;
117
- [SerializeField]
118
- private string _androidId;
119
- [SerializeField]
120
- private string _pseudoId;
121
- [SerializeField]
122
- private string _amaDeviceId;
123
- [SerializeField]
124
- private string _appsFlyerId;
125
- [SerializeField]
126
- private string _installationId;
127
-
128
- private const string ALPHANUMERIC_HYPHEN_PATTERN = @"^(?=.*\d)(?=.*[a-zA-Z])(?=.*-).+$";
129
- private const string ALPHANUMERIC_PATTERN = @"^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z\d]+$";
130
- private const string NUMERIC_HYPHEN_PATTERN = @"^(?=.*\d)(?=.*-)[\d-]+$";
131
-
132
- private const string AMA_DEVICE_ID_KEY = "ama_device_id";
133
- private const float TIME_OUT = 5f;
134
- private const float WAIT_TIME = 0.5f;
135
- private WaitForSecondsRealtime waitForDuration = new WaitForSecondsRealtime(WAIT_TIME);
136
-
137
- internal void InitModule()
138
- {
139
- User.LoadJsonFromFile();
140
-
141
- // Always get the latest advertising id
142
- GetAdvertisingId();
143
- }
144
-
145
- internal void StartModule()
146
- {
147
- UpdateUserId();
148
- }
149
108
 
150
- // internal IEnumerator Init()
151
- // {
152
- // float time = 0;
153
- // while (!User.IsAmaDeviceIdExist())
154
- // {
155
- // yield return waitForDuration;
156
- // time += WAIT_TIME;
157
- // if (time <= TIME_OUT) continue;
158
- // Logging.LogWarning($"| UserProfile <init> timeout: {TIME_OUT} (ama_device_id not exist)");
159
- // break;
160
- // }
161
- // }
162
-
163
- internal void UpdateUserId()
109
+ public void UpdateUserId()
164
110
  {
165
111
  #if UNITY_ANDROID
166
112
  if (!string.IsNullOrWhiteSpace(_gaid))
@@ -168,33 +114,35 @@ namespace Amanotes.Core
168
114
  UserId = $"GAID-{_gaid}";
169
115
  return;
170
116
  }
171
-
172
- if (!string.IsNullOrWhiteSpace(_androidId))
173
- {
174
- UserId = $"ADR-{_androidId}";
175
- return;
176
- }
177
117
  #endif
178
-
179
118
  #if UNITY_IOS
180
119
  if (!string.IsNullOrWhiteSpace(_idfa))
181
120
  {
182
121
  UserId = $"IDFA-{_idfa}";
183
122
  return;
184
123
  }
124
+ #endif
185
125
 
186
- if (!string.IsNullOrWhiteSpace(_idfv))
126
+ if (!string.IsNullOrWhiteSpace(_pseudoId))
187
127
  {
188
- UserId = $"IDFV-{_idfv}";
128
+ UserId = $"FRB-{_pseudoId}";
189
129
  return;
190
130
  }
191
- #endif
192
131
 
193
- if (!string.IsNullOrWhiteSpace(_pseudoId))
132
+ #if UNITY_ANDROID
133
+ if (!string.IsNullOrWhiteSpace(_androidId))
194
134
  {
195
- UserId = $"FRB-{_pseudoId}";
135
+ UserId = $"ADR-{_androidId}";
196
136
  return;
197
137
  }
138
+ #endif
139
+ #if UNITY_IOS
140
+ if (!string.IsNullOrWhiteSpace(_idfv))
141
+ {
142
+ UserId = $"IDFV-{_idfv}";
143
+ return;
144
+ }
145
+ #endif
198
146
 
199
147
  if (!string.IsNullOrWhiteSpace(_amaDeviceId))
200
148
  {
@@ -214,71 +162,105 @@ namespace Amanotes.Core
214
162
  return;
215
163
  }
216
164
  }
165
+ }
166
+
167
+ public partial class UserProfile //INTERNAL
168
+ {
169
+ [SerializeField]
170
+ private string _userId;
171
+ [SerializeField]
172
+ private string _gaid;
173
+ [SerializeField]
174
+ private string _idfa;
175
+ [SerializeField]
176
+ private string _idfv;
177
+ [SerializeField]
178
+ private string _androidId;
179
+ [SerializeField]
180
+ private string _pseudoId;
181
+ [SerializeField]
182
+ private string _amaDeviceId;
183
+ [SerializeField]
184
+ private string _appsFlyerId;
185
+ [SerializeField]
186
+ private string _installationId;
187
+
188
+ private const string ALPHANUMERIC_HYPHEN_PATTERN = @"^(?=.*\d)(?=.*[a-zA-Z])(?=.*-).+$";
189
+ private const string ALPHANUMERIC_PATTERN = @"^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z\d]+$";
190
+ private const string NUMERIC_HYPHEN_PATTERN = @"^(?=.*\d)(?=.*-)[\d-]+$";
217
191
 
218
- private bool IsAmaDeviceIdExist()
192
+ private const string AMA_DEVICE_ID_KEY = "ama_device_id";
193
+
194
+ internal void InitModule()
219
195
  {
220
- if (!string.IsNullOrEmpty(_amaDeviceId))
221
- {
222
- Logging.Log($"AmaDeviceId is already existed: {_amaDeviceId}");
223
- return true;
224
- }
225
- return false;
196
+ User.LoadJsonFromFile();
197
+
198
+ #if UNITY_ANDROID
199
+ AndroidId = SystemInfo.deviceUniqueIdentifier;
200
+ #elif UNITY_IOS
201
+ IDFV = SystemInfo.deviceUniqueIdentifier;
202
+ #endif
203
+
204
+ // Always get the latest advertising id
205
+ GetAdvertisingId();
226
206
  }
227
207
 
208
+ internal void StartModule()
209
+ {
210
+ UpdateUserId();
211
+ Logging.Log($"[UserProfile] user_id: {_userId}");
212
+ }
213
+
228
214
  private void SetAdvertisingID(string id)
229
215
  {
230
216
  switch (Application.platform)
231
217
  {
232
218
  case RuntimePlatform.IPhonePlayer:
233
219
  IDFA = id;
234
- IDFV = SystemInfo.deviceUniqueIdentifier;
235
220
  break;
236
221
  case RuntimePlatform.Android:
237
222
  GAId = id;
238
- AndroidId = SystemInfo.deviceUniqueIdentifier;
239
- break;
240
- default:
241
- // Logging.Log($"[UserProfile] There is no advertising ID on {Application.platform}");
242
223
  break;
243
224
  }
244
225
  }
245
226
 
246
227
  private void GetAdvertisingId()
247
228
  {
248
- float time = Time.realtimeSinceStartup;
249
-
250
229
  AdvertisingIdFetcher.RequestAdvertisingId(advertisingId =>
251
230
  {
252
- SetAdvertisingID(advertisingId);
253
- switch (Application.platform)
231
+ GDKUtils.DelayCall(0, () =>
254
232
  {
255
- case RuntimePlatform.IPhonePlayer:
256
- string v = KeyChain.GetKeyChain(AMA_DEVICE_ID_KEY);
257
- if (string.IsNullOrEmpty(v))
258
- {
259
- v = Guid.NewGuid().ToString();
260
- KeyChain.SetKeyChain(AMA_DEVICE_ID_KEY, v);
261
- }
262
- AmaDeviceId = v;
263
- break;
233
+ SetAdvertisingID(advertisingId);
234
+ switch (Application.platform)
235
+ {
236
+ case RuntimePlatform.IPhonePlayer:
237
+ string v = KeyChain.GetKeyChain(AMA_DEVICE_ID_KEY);
238
+ if (string.IsNullOrEmpty(v))
239
+ {
240
+ v = Guid.NewGuid().ToString();
241
+ KeyChain.SetKeyChain(AMA_DEVICE_ID_KEY, v);
242
+ }
243
+ AmaDeviceId = v;
244
+ break;
264
245
 
265
- case RuntimePlatform.Android:
266
- string cachedAmaDeviceId = PlayerPrefs.GetString(AMA_DEVICE_ID_KEY);
267
- if (string.IsNullOrEmpty(cachedAmaDeviceId))
268
- {
269
- cachedAmaDeviceId = SystemInfo.deviceUniqueIdentifier;
270
- PlayerPrefs.SetString(AMA_DEVICE_ID_KEY, cachedAmaDeviceId);
271
- }
272
- AmaDeviceId = cachedAmaDeviceId;
273
- break;
246
+ case RuntimePlatform.Android:
247
+ string cachedAmaDeviceId = PlayerPrefs.GetString(AMA_DEVICE_ID_KEY);
248
+ if (string.IsNullOrEmpty(cachedAmaDeviceId))
249
+ {
250
+ cachedAmaDeviceId = SystemInfo.deviceUniqueIdentifier;
251
+ PlayerPrefs.SetString(AMA_DEVICE_ID_KEY, cachedAmaDeviceId);
252
+ }
253
+ AmaDeviceId = cachedAmaDeviceId;
254
+ break;
274
255
 
275
- default:
276
- AmaDeviceId = SystemInfo.deviceUniqueIdentifier;
277
- break;
278
- }
256
+ default:
257
+ AmaDeviceId = SystemInfo.deviceUniqueIdentifier;
258
+ break;
259
+ }
279
260
 
280
- Logging.Log($"Generate AmaDeviceId completed: {_amaDeviceId}");
281
- User.Save();
261
+ Logging.Log($"[UserProfile] ama_device_id: {_amaDeviceId}");
262
+ Save();
263
+ });
282
264
  });
283
265
  }
284
266