expo-gaode-map 2.2.7-next.0 → 2.2.8-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.
|
@@ -32,10 +32,28 @@ class ExpoGaodeMapModule : Module() {
|
|
|
32
32
|
|
|
33
33
|
// 🚀 如果用户已同意隐私协议,自动启动预加载(延迟2秒)
|
|
34
34
|
if (SDKInitializer.isPrivacyAgreed()) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
// 尝试从 AndroidManifest.xml 读取并设置 API Key
|
|
36
|
+
val apiKey = context.packageManager
|
|
37
|
+
.getApplicationInfo(context.packageName, android.content.pm.PackageManager.GET_META_DATA)
|
|
38
|
+
.metaData?.getString("com.amap.api.v2.apikey")
|
|
39
|
+
|
|
40
|
+
if (!apiKey.isNullOrEmpty()) {
|
|
41
|
+
try {
|
|
42
|
+
com.amap.api.maps.MapsInitializer.setApiKey(apiKey)
|
|
43
|
+
com.amap.api.location.AMapLocationClient.setApiKey(apiKey)
|
|
44
|
+
android.util.Log.d("ExpoGaodeMap", "✅ 从 AndroidManifest.xml 读取并设置 API Key 成功")
|
|
45
|
+
|
|
46
|
+
// 只有在 API Key 已设置的情况下才启动预加载
|
|
47
|
+
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
|
48
|
+
android.util.Log.i("ExpoGaodeMap", "🚀 自动启动地图预加载")
|
|
49
|
+
MapPreloadManager.startPreload(context, poolSize = 1)
|
|
50
|
+
}, 2000)
|
|
51
|
+
} catch (e: Exception) {
|
|
52
|
+
android.util.Log.w("ExpoGaodeMap", "设置 API Key 失败: ${e.message}")
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
android.util.Log.w("ExpoGaodeMap", "⚠️ AndroidManifest.xml 未找到 API Key,跳过自动预加载")
|
|
56
|
+
}
|
|
39
57
|
}
|
|
40
58
|
} catch (e: Exception) {
|
|
41
59
|
android.util.Log.w("ExpoGaodeMap", "恢复隐私状态时出现问题: ${e.message}")
|
|
@@ -54,6 +72,24 @@ class ExpoGaodeMapModule : Module() {
|
|
|
54
72
|
|
|
55
73
|
// 🚀 用户首次同意隐私协议后,自动启动预加载
|
|
56
74
|
if (hasAgreed) {
|
|
75
|
+
// 在用户同意后,如果尚未设置 API Key,则尝试从 AndroidManifest.xml 读取并设置
|
|
76
|
+
try {
|
|
77
|
+
val apiKey = context.packageManager
|
|
78
|
+
.getApplicationInfo(context.packageName, android.content.pm.PackageManager.GET_META_DATA)
|
|
79
|
+
.metaData?.getString("com.amap.api.v2.apikey")
|
|
80
|
+
|
|
81
|
+
if (!apiKey.isNullOrEmpty()) {
|
|
82
|
+
com.amap.api.maps.MapsInitializer.setApiKey(apiKey)
|
|
83
|
+
com.amap.api.location.AMapLocationClient.setApiKey(apiKey)
|
|
84
|
+
android.util.Log.d("ExpoGaodeMap", "✅ 从 AndroidManifest.xml 读取并设置 API Key 成功")
|
|
85
|
+
} else {
|
|
86
|
+
android.util.Log.w("ExpoGaodeMap", "⚠️ AndroidManifest.xml 未找到 API Key,后续需通过 initSDK 提供 androidKey")
|
|
87
|
+
}
|
|
88
|
+
} catch (e: Exception) {
|
|
89
|
+
android.util.Log.w("ExpoGaodeMap", "读取 API Key 失败: ${e.message}")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 延迟启动预加载
|
|
57
93
|
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
|
58
94
|
if (!MapPreloadManager.hasPreloadedMapView() &&
|
|
59
95
|
!(MapPreloadManager.getStatus()["isPreloading"] as Boolean)) {
|
|
@@ -37,10 +37,26 @@ public class ExpoGaodeMapModule: Module {
|
|
|
37
37
|
MAMapView.updatePrivacyAgree(AMapPrivacyAgreeStatus.didAgree)
|
|
38
38
|
print("🔁 ExpoGaodeMap: 已从缓存恢复隐私同意状态: true")
|
|
39
39
|
|
|
40
|
+
// 尝试从 Info.plist 读取并设置 API Key
|
|
41
|
+
if AMapServices.shared().apiKey == nil || AMapServices.shared().apiKey?.isEmpty == true {
|
|
42
|
+
if let plistKey = Bundle.main.infoDictionary?["AMapApiKey"] as? String, !plistKey.isEmpty {
|
|
43
|
+
AMapServices.shared().apiKey = plistKey
|
|
44
|
+
AMapServices.shared().enableHTTPS = true
|
|
45
|
+
print("✅ ExpoGaodeMap: OnCreate 从 Info.plist 读取并设置 AMapApiKey 成功")
|
|
46
|
+
} else {
|
|
47
|
+
print("⚠️ ExpoGaodeMap: Info.plist 未找到 AMapApiKey,跳过自动预加载")
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
// 🚀 自动启动预加载(延迟2秒,避免影响启动速度)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
// 只有在 API Key 已设置的情况下才启动预加载
|
|
53
|
+
if let apiKey = AMapServices.shared().apiKey, !apiKey.isEmpty {
|
|
54
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
|
|
55
|
+
print("🚀 ExpoGaodeMap: 自动启动地图预加载")
|
|
56
|
+
MapPreloadManager.shared.startPreload(poolSize: 1)
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
print("⚠️ ExpoGaodeMap: API Key 未设置,跳过自动预加载")
|
|
44
60
|
}
|
|
45
61
|
} else {
|
|
46
62
|
print("ℹ️ ExpoGaodeMap: 未发现已同意记录,等待用户同意后再使用 SDK")
|