expo-gaode-map 2.2.4-next.0 → 2.2.5-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 {
|