expo-gaode-map 2.2.4-next.0 → 2.2.6-next.0

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.
@@ -22,6 +22,13 @@ class ExpoGaodeMapModule : Module() {
22
22
  override fun definition() = ModuleDefinition {
23
23
  Name("ExpoGaodeMap")
24
24
 
25
+ // 在模块加载时尝试从本地缓存恢复隐私同意状态,避免每次启动都必须 JS 调用
26
+ try {
27
+ SDKInitializer.restorePrivacyState(appContext.reactContext!!)
28
+ } catch (e: Exception) {
29
+ android.util.Log.w("ExpoGaodeMap", "恢复隐私状态时出现问题: ${e.message}")
30
+ }
31
+
25
32
  // ==================== 隐私合规管理 ====================
26
33
 
27
34
  /**
@@ -1,12 +1,13 @@
1
1
  package expo.modules.gaodemap.modules
2
2
 
3
3
  import android.content.Context
4
+ import android.content.SharedPreferences
4
5
  import com.amap.api.location.AMapLocationClient
5
6
  import com.amap.api.maps.MapsInitializer
6
7
 
7
8
  /**
8
9
  * SDK 初始化管理器
9
- *
10
+ *
10
11
  * 负责:
11
12
  * - 初始化高德地图 SDK
12
13
  * - 初始化高德定位 SDK
@@ -15,8 +16,14 @@ import com.amap.api.maps.MapsInitializer
15
16
  */
16
17
  object SDKInitializer {
17
18
 
18
- /** 隐私协议是否已同意 */
19
+ /** 隐私协议是否已同意(进程内缓存) */
19
20
  private var privacyAgreed = false
21
+
22
+ private const val PREFS_NAME = "expo_gaode_map_prefs"
23
+ private const val KEY_PRIVACY_AGREED = "privacy_agreed"
24
+
25
+ private fun prefs(context: Context): SharedPreferences =
26
+ context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
20
27
 
21
28
  /**
22
29
  * 更新隐私合规状态
@@ -42,8 +49,36 @@ object SDKInitializer {
42
49
  AMapLocationClient.updatePrivacyAgree(context, false)
43
50
  android.util.Log.w("ExpoGaodeMap", "⚠️ 用户未同意隐私协议,SDK 功能将受限")
44
51
  }
52
+
53
+ // 持久化状态,供下次启动自动恢复
54
+ try {
55
+ prefs(context).edit().putBoolean(KEY_PRIVACY_AGREED, hasAgreed).apply()
56
+ } catch (e: Exception) {
57
+ android.util.Log.w("ExpoGaodeMap", "持久化隐私状态失败: ${e.message}")
58
+ }
45
59
  }
46
60
 
61
+ /**
62
+ * 从本地存储恢复隐私合规状态(在应用启动或模块加载时调用)
63
+ * 若无记录则保持默认 false,不抛出异常。
64
+ */
65
+ fun restorePrivacyState(context: Context) {
66
+ try {
67
+ val saved = prefs(context).getBoolean(KEY_PRIVACY_AGREED, false)
68
+ privacyAgreed = saved
69
+
70
+ // 同步到 SDK
71
+ MapsInitializer.updatePrivacyShow(context, true, true)
72
+ AMapLocationClient.updatePrivacyShow(context, true, true)
73
+ MapsInitializer.updatePrivacyAgree(context, saved)
74
+ AMapLocationClient.updatePrivacyAgree(context, saved)
75
+
76
+ android.util.Log.d("ExpoGaodeMap", "🔁 已从缓存恢复隐私状态: $saved")
77
+ } catch (e: Exception) {
78
+ android.util.Log.w("ExpoGaodeMap", "恢复隐私状态失败: ${e.message}")
79
+ }
80
+ }
81
+
47
82
  /**
48
83
  * 检查隐私协议是否已同意
49
84
  *
@@ -79,7 +114,7 @@ object SDKInitializer {
79
114
 
80
115
  /**
81
116
  * 获取 SDK 版本号
82
- *
117
+ *
83
118
  * @return SDK 版本字符串
84
119
  */
85
120
  fun getVersion(): String {
@@ -18,16 +18,27 @@ public class ExpoGaodeMapModule: Module {
18
18
  private var permissionManager: PermissionManager?
19
19
  /// 隐私协议是否已同意(模块级别跟踪)
20
20
  private static var privacyAgreed: Bool = false
21
+ /// 隐私同意持久化 Key
22
+ private static let privacyDefaultsKey = "expo_gaode_map_privacy_agreed"
21
23
 
22
24
  public func definition() -> ModuleDefinition {
23
25
  Name("ExpoGaodeMap")
24
26
 
25
- // 模块初始化时不设置隐私合规
26
- // 需要在用户同意隐私协议后手动调用 updatePrivacyCompliance 方法
27
+ // 模块初始化:尝试从本地缓存恢复隐私同意状态
27
28
  OnCreate {
28
- // 仅更新隐私信息显示状态,不表示用户已同意
29
+ // 先确保隐私信息展示状态
29
30
  MAMapView.updatePrivacyShow(AMapPrivacyShowStatus.didShow, privacyInfo: AMapPrivacyInfoStatus.didContain)
30
- print("ℹ️ ExpoGaodeMap: 隐私信息已更新,但需要用户同意隐私协议才能使用 SDK")
31
+
32
+ // 从 UserDefaults 恢复上次的同意状态(默认 false)
33
+ let saved = UserDefaults.standard.bool(forKey: ExpoGaodeMapModule.privacyDefaultsKey)
34
+ ExpoGaodeMapModule.privacyAgreed = saved
35
+ if saved {
36
+ // 同步到 SDK
37
+ MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
38
+ print("🔁 ExpoGaodeMap: 已从缓存恢复隐私同意状态: true")
39
+ } else {
40
+ print("ℹ️ ExpoGaodeMap: 未发现已同意记录,等待用户同意后再使用 SDK")
41
+ }
31
42
  }
32
43
 
33
44
  // ==================== 隐私合规管理 ====================
@@ -37,10 +48,15 @@ public class ExpoGaodeMapModule: Module {
37
48
  * 必须在用户同意隐私协议后调用
38
49
  */
39
50
  Function("updatePrivacyCompliance") { (hasAgreed: Bool) in
51
+ // 更新内存状态
40
52
  ExpoGaodeMapModule.privacyAgreed = hasAgreed
53
+ // 持久化到本地,供下次启动自动恢复
54
+ UserDefaults.standard.set(hasAgreed, forKey: ExpoGaodeMapModule.privacyDefaultsKey)
55
+
41
56
  if hasAgreed {
57
+ // 同步到 SDK
42
58
  MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
43
- print("✅ ExpoGaodeMap: 用户已同意隐私协议,可以使用 SDK")
59
+ print("✅ ExpoGaodeMap: 用户已同意隐私协议,可以使用 SDK(状态已持久化)")
44
60
 
45
61
  // 在用户同意后,如果尚未设置 API Key,则尝试从 Info.plist 读取并设置
46
62
  if AMapServices.shared().apiKey == nil || AMapServices.shared().apiKey?.isEmpty == true {
@@ -54,7 +70,7 @@ public class ExpoGaodeMapModule: Module {
54
70
  }
55
71
  } else {
56
72
  MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.notAgree)
57
- print("⚠️ ExpoGaodeMap: 用户未同意隐私协议,SDK 功能将受限")
73
+ print("⚠️ ExpoGaodeMap: 用户未同意隐私协议,SDK 功能将受限(状态已持久化)")
58
74
  }
59
75
  }
60
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "2.2.4-next.0",
3
+ "version": "2.2.6-next.0",
4
4
  "description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",