expo-gaode-map-navigation 1.1.5 → 1.1.7
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.
- package/README.md +213 -73
- package/android/build.gradle +10 -0
- package/android/src/main/cpp/CMakeLists.txt +24 -0
- package/android/src/main/cpp/cluster_jni.cpp +848 -0
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapModule.kt +616 -92
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapOfflineModule.kt +493 -0
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapView.kt +230 -14
- package/android/src/main/java/expo/modules/gaodemap/map/ExpoGaodeMapViewModule.kt +37 -27
- package/android/src/main/java/expo/modules/gaodemap/map/MapPreloadManager.kt +494 -0
- package/android/src/main/java/expo/modules/gaodemap/map/companion/BitmapDescriptorCache.kt +30 -0
- package/android/src/main/java/expo/modules/gaodemap/map/companion/IconBitmapCache.kt +37 -0
- package/android/src/main/java/expo/modules/gaodemap/map/managers/UIManager.kt +76 -0
- package/android/src/main/java/expo/modules/gaodemap/map/modules/LocationManager.kt +15 -3
- package/android/src/main/java/expo/modules/gaodemap/map/modules/SDKInitializer.kt +4 -59
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/CircleView.kt +9 -12
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/CircleViewModule.kt +5 -6
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/ClusterView.kt +539 -66
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/ClusterViewModule.kt +17 -1
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/HeatMapView.kt +165 -33
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/HeatMapViewModule.kt +15 -3
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MarkerView.kt +1249 -672
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MarkerViewModule.kt +40 -17
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MultiPointView.kt +177 -22
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/MultiPointViewModule.kt +11 -3
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolygonView.kt +57 -14
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolygonViewModule.kt +9 -5
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolylineView.kt +90 -63
- package/android/src/main/java/expo/modules/gaodemap/map/overlays/PolylineViewModule.kt +7 -3
- package/android/src/main/java/expo/modules/gaodemap/map/services/LocationForegroundService.kt +3 -2
- package/android/src/main/java/expo/modules/gaodemap/map/utils/BitmapDescriptorCache.kt +20 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/ClusterNative.kt +13 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/ColorParser.kt +20 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/GeometryUtils.kt +515 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/LatLngParser.kt +91 -0
- package/android/src/main/java/expo/modules/gaodemap/map/utils/PermissionHelper.kt +248 -0
- package/build/ExpoGaodeMapNaviView.d.ts +7 -7
- package/build/ExpoGaodeMapNaviView.js +10 -11
- package/build/ExpoGaodeMapNavigationModule.d.ts +2 -1
- package/build/index.d.ts +35 -33
- package/build/index.js +70 -106
- package/build/map/ExpoGaodeMapModule.d.ts +2 -201
- package/build/map/ExpoGaodeMapModule.js +586 -18
- package/build/map/ExpoGaodeMapOfflineModule.d.ts +139 -0
- package/build/map/ExpoGaodeMapOfflineModule.js +8 -0
- package/build/map/ExpoGaodeMapView.js +66 -58
- package/build/map/components/FoldableMapView.d.ts +38 -0
- package/build/map/components/FoldableMapView.js +209 -0
- package/build/map/components/MapContext.d.ts +12 -0
- package/build/map/components/MapContext.js +54 -0
- package/build/map/components/MapUI.d.ts +18 -0
- package/build/map/components/MapUI.js +29 -0
- package/build/map/components/overlays/Circle.js +34 -3
- package/build/map/components/overlays/Cluster.d.ts +3 -1
- package/build/map/components/overlays/Cluster.js +31 -2
- package/build/map/components/overlays/HeatMap.d.ts +3 -1
- package/build/map/components/overlays/HeatMap.js +33 -3
- package/build/map/components/overlays/Marker.d.ts +1 -1
- package/build/map/components/overlays/Marker.js +37 -32
- package/build/map/components/overlays/MultiPoint.js +1 -1
- package/build/map/components/overlays/Polygon.js +30 -3
- package/build/map/components/overlays/Polyline.js +36 -3
- package/build/map/index.d.ts +25 -5
- package/build/map/index.js +59 -18
- package/build/map/types/common.types.d.ts +40 -0
- package/build/map/types/common.types.js +0 -4
- package/build/map/types/index.d.ts +3 -2
- package/build/map/types/map-view.types.d.ts +108 -3
- package/build/map/types/native-module.types.d.ts +363 -0
- package/build/map/types/native-module.types.js +5 -0
- package/build/map/types/offline.types.d.ts +132 -0
- package/build/map/types/offline.types.js +5 -0
- package/build/map/types/overlays.types.d.ts +137 -24
- package/build/map/utils/ErrorHandler.d.ts +110 -0
- package/build/map/utils/ErrorHandler.js +421 -0
- package/build/map/utils/GeoUtils.d.ts +20 -0
- package/build/map/utils/GeoUtils.js +76 -0
- package/build/map/utils/OfflineMapManager.d.ts +148 -0
- package/build/map/utils/OfflineMapManager.js +217 -0
- package/build/map/utils/PermissionUtils.d.ts +91 -0
- package/build/map/utils/PermissionUtils.js +255 -0
- package/build/map/utils/PlatformDetector.d.ts +102 -0
- package/build/map/utils/PlatformDetector.js +186 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +1 -0
- package/build/types/native-module.types.d.ts +69 -0
- package/build/types/native-module.types.js +2 -0
- package/build/types/naviview.types.d.ts +1 -1
- package/expo-module.config.json +12 -10
- package/ios/ExpoGaodeMapNavigation.podspec +9 -0
- package/ios/map/ExpoGaodeMapModule.swift +485 -75
- package/ios/map/ExpoGaodeMapOfflineModule.swift +479 -0
- package/ios/map/ExpoGaodeMapView.swift +611 -62
- package/ios/map/ExpoGaodeMapViewModule.swift +48 -26
- package/ios/map/MapPreloadManager.swift +348 -0
- package/ios/map/cpp/ClusterEngine.cpp +110 -0
- package/ios/map/cpp/ClusterEngine.hpp +20 -0
- package/ios/map/cpp/ColorParser.cpp +135 -0
- package/ios/map/cpp/ColorParser.hpp +14 -0
- package/ios/map/cpp/GeometryEngine.cpp +574 -0
- package/ios/map/cpp/GeometryEngine.hpp +159 -0
- package/ios/map/cpp/QuadTree.cpp +92 -0
- package/ios/map/cpp/QuadTree.hpp +42 -0
- package/ios/map/cpp/README.md +55 -0
- package/ios/map/managers/UIManager.swift +72 -1
- package/ios/map/modules/LocationManager.swift +123 -166
- package/ios/map/overlays/CircleView.swift +16 -32
- package/ios/map/overlays/CircleViewModule.swift +12 -12
- package/ios/map/overlays/ClusterAnnotation.swift +32 -0
- package/ios/map/overlays/ClusterView.swift +331 -45
- package/ios/map/overlays/ClusterViewModule.swift +20 -6
- package/ios/map/overlays/HeatMapView.swift +135 -32
- package/ios/map/overlays/HeatMapViewModule.swift +20 -8
- package/ios/map/overlays/MarkerView.swift +613 -130
- package/ios/map/overlays/MarkerViewModule.swift +38 -18
- package/ios/map/overlays/MultiPointView.swift +168 -10
- package/ios/map/overlays/MultiPointViewModule.swift +27 -5
- package/ios/map/overlays/PolygonView.swift +62 -23
- package/ios/map/overlays/PolygonViewModule.swift +18 -12
- package/ios/map/overlays/PolylineView.swift +21 -13
- package/ios/map/overlays/PolylineViewModule.swift +18 -12
- package/ios/map/utils/ClusterNative.h +96 -0
- package/ios/map/utils/ClusterNative.mm +377 -0
- package/ios/map/utils/ColorParser.swift +12 -1
- package/ios/map/utils/CppBridging.mm +13 -0
- package/ios/map/utils/GeometryUtils.swift +34 -0
- package/ios/map/utils/LatLngParser.swift +87 -0
- package/ios/map/utils/PermissionManager.swift +135 -6
- package/package.json +3 -2
- package/shared/cpp/ClusterEngine.cpp +110 -0
- package/shared/cpp/ClusterEngine.hpp +20 -0
- package/shared/cpp/ColorParser.cpp +135 -0
- package/shared/cpp/ColorParser.hpp +14 -0
- package/shared/cpp/GeometryEngine.cpp +574 -0
- package/shared/cpp/GeometryEngine.hpp +159 -0
- package/shared/cpp/QuadTree.cpp +92 -0
- package/shared/cpp/QuadTree.hpp +42 -0
- package/shared/cpp/README.md +55 -0
- package/shared/cpp/tests/benchmark_js.js +41 -0
- package/shared/cpp/tests/run.sh +17 -0
- package/shared/cpp/tests/test_main.cpp +276 -0
- package/build/map/ExpoGaodeMap.types.d.ts +0 -41
- package/build/map/ExpoGaodeMap.types.js +0 -24
- package/build/map/utils/EventManager.d.ts +0 -10
- package/build/map/utils/EventManager.js +0 -26
- package/build/map/utils/ModuleLoader.d.ts +0 -73
- package/build/map/utils/ModuleLoader.js +0 -112
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 离线地图便捷 API
|
|
4
|
+
* 提供更友好的 API 接口和事件监听
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.OfflineMapManager = void 0;
|
|
11
|
+
const ExpoGaodeMapOfflineModule_1 = __importDefault(require("../ExpoGaodeMapOfflineModule"));
|
|
12
|
+
/**
|
|
13
|
+
* 离线地图管理类
|
|
14
|
+
*/
|
|
15
|
+
class OfflineMapManager {
|
|
16
|
+
// ==================== 地图列表管理 ====================
|
|
17
|
+
/**
|
|
18
|
+
* 获取所有可下载的城市列表
|
|
19
|
+
*/
|
|
20
|
+
static async getAvailableCities() {
|
|
21
|
+
return ExpoGaodeMapOfflineModule_1.default.getAvailableCities();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 获取所有省份列表
|
|
25
|
+
*/
|
|
26
|
+
static async getAvailableProvinces() {
|
|
27
|
+
return ExpoGaodeMapOfflineModule_1.default.getAvailableProvinces();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 根据省份代码获取城市列表
|
|
31
|
+
*/
|
|
32
|
+
static async getCitiesByProvince(provinceCode) {
|
|
33
|
+
return ExpoGaodeMapOfflineModule_1.default.getCitiesByProvince(provinceCode);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 获取已下载的地图列表
|
|
37
|
+
*/
|
|
38
|
+
static async getDownloadedMaps() {
|
|
39
|
+
return ExpoGaodeMapOfflineModule_1.default.getDownloadedMaps();
|
|
40
|
+
}
|
|
41
|
+
// ==================== 下载管理 ====================
|
|
42
|
+
/**
|
|
43
|
+
* 开始下载离线地图
|
|
44
|
+
*/
|
|
45
|
+
static async startDownload(config) {
|
|
46
|
+
return ExpoGaodeMapOfflineModule_1.default.startDownload(config);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 暂停下载
|
|
50
|
+
*/
|
|
51
|
+
static async pauseDownload(cityCode) {
|
|
52
|
+
return ExpoGaodeMapOfflineModule_1.default.pauseDownload(cityCode);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 恢复下载
|
|
56
|
+
*/
|
|
57
|
+
static async resumeDownload(cityCode) {
|
|
58
|
+
return ExpoGaodeMapOfflineModule_1.default.resumeDownload(cityCode);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 取消下载
|
|
62
|
+
*/
|
|
63
|
+
static async cancelDownload(cityCode) {
|
|
64
|
+
return ExpoGaodeMapOfflineModule_1.default.cancelDownload(cityCode);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 删除离线地图
|
|
68
|
+
*/
|
|
69
|
+
static async deleteMap(cityCode) {
|
|
70
|
+
return ExpoGaodeMapOfflineModule_1.default.deleteMap(cityCode);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 更新离线地图
|
|
74
|
+
*/
|
|
75
|
+
static async updateMap(cityCode) {
|
|
76
|
+
return ExpoGaodeMapOfflineModule_1.default.updateMap(cityCode);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 检查是否有可用更新
|
|
80
|
+
*/
|
|
81
|
+
static async checkUpdate(cityCode) {
|
|
82
|
+
return ExpoGaodeMapOfflineModule_1.default.checkUpdate(cityCode);
|
|
83
|
+
}
|
|
84
|
+
// ==================== 状态查询 ====================
|
|
85
|
+
/**
|
|
86
|
+
* 检查地图是否已下载
|
|
87
|
+
*/
|
|
88
|
+
static async isMapDownloaded(cityCode) {
|
|
89
|
+
return ExpoGaodeMapOfflineModule_1.default.isMapDownloaded(cityCode);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 获取地图下载状态
|
|
93
|
+
*/
|
|
94
|
+
static async getMapStatus(cityCode) {
|
|
95
|
+
return ExpoGaodeMapOfflineModule_1.default.getMapStatus(cityCode);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 获取所有下载任务的总进度
|
|
99
|
+
*/
|
|
100
|
+
static async getTotalProgress() {
|
|
101
|
+
return ExpoGaodeMapOfflineModule_1.default.getTotalProgress();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 获取当前正在下载的城市列表
|
|
105
|
+
*/
|
|
106
|
+
static async getDownloadingCities() {
|
|
107
|
+
return ExpoGaodeMapOfflineModule_1.default.getDownloadingCities();
|
|
108
|
+
}
|
|
109
|
+
// ==================== 存储管理 ====================
|
|
110
|
+
/**
|
|
111
|
+
* 获取离线地图占用的存储空间(字节)
|
|
112
|
+
*/
|
|
113
|
+
static async getStorageSize() {
|
|
114
|
+
return ExpoGaodeMapOfflineModule_1.default.getStorageSize();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 获取详细的存储信息
|
|
118
|
+
*/
|
|
119
|
+
static async getStorageInfo() {
|
|
120
|
+
return ExpoGaodeMapOfflineModule_1.default.getStorageInfo();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 清理所有离线地图
|
|
124
|
+
*/
|
|
125
|
+
static async clearAllMaps() {
|
|
126
|
+
return ExpoGaodeMapOfflineModule_1.default.clearAllMaps();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 设置离线地图存储路径
|
|
130
|
+
*/
|
|
131
|
+
static setStoragePath(path) {
|
|
132
|
+
ExpoGaodeMapOfflineModule_1.default.setStoragePath(path);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 获取离线地图存储路径
|
|
136
|
+
*/
|
|
137
|
+
static async getStoragePath() {
|
|
138
|
+
return ExpoGaodeMapOfflineModule_1.default.getStoragePath();
|
|
139
|
+
}
|
|
140
|
+
// ==================== 批量操作 ====================
|
|
141
|
+
/**
|
|
142
|
+
* 批量下载地图
|
|
143
|
+
*/
|
|
144
|
+
static async batchDownload(cityCodes, allowCellular = false) {
|
|
145
|
+
return ExpoGaodeMapOfflineModule_1.default.batchDownload(cityCodes, allowCellular);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 批量删除地图
|
|
149
|
+
*/
|
|
150
|
+
static async batchDelete(cityCodes) {
|
|
151
|
+
return ExpoGaodeMapOfflineModule_1.default.batchDelete(cityCodes);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 批量更新地图
|
|
155
|
+
*/
|
|
156
|
+
static async batchUpdate(cityCodes) {
|
|
157
|
+
return ExpoGaodeMapOfflineModule_1.default.batchUpdate(cityCodes);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 暂停所有下载任务
|
|
161
|
+
*/
|
|
162
|
+
static async pauseAllDownloads() {
|
|
163
|
+
return ExpoGaodeMapOfflineModule_1.default.pauseAllDownloads();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 恢复所有下载任务
|
|
167
|
+
*/
|
|
168
|
+
static async resumeAllDownloads() {
|
|
169
|
+
return ExpoGaodeMapOfflineModule_1.default.resumeAllDownloads();
|
|
170
|
+
}
|
|
171
|
+
// ==================== 事件监听 ====================
|
|
172
|
+
/**
|
|
173
|
+
* 监听下载进度事件
|
|
174
|
+
*/
|
|
175
|
+
static addDownloadProgressListener(listener) {
|
|
176
|
+
return ExpoGaodeMapOfflineModule_1.default.addListener('onDownloadProgress', listener);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 监听下载完成事件
|
|
180
|
+
*/
|
|
181
|
+
static addDownloadCompleteListener(listener) {
|
|
182
|
+
return ExpoGaodeMapOfflineModule_1.default.addListener('onDownloadComplete', listener);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 监听下载错误事件
|
|
186
|
+
*/
|
|
187
|
+
static addDownloadErrorListener(listener) {
|
|
188
|
+
return ExpoGaodeMapOfflineModule_1.default.addListener('onDownloadError', listener);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 监听下载暂停事件
|
|
192
|
+
*/
|
|
193
|
+
static addDownloadPausedListener(listener) {
|
|
194
|
+
return ExpoGaodeMapOfflineModule_1.default.addListener('onDownloadPaused', listener);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 监听下载取消事件
|
|
198
|
+
*/
|
|
199
|
+
static addDownloadCancelledListener(listener) {
|
|
200
|
+
return ExpoGaodeMapOfflineModule_1.default.addListener('onDownloadCancelled', listener);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 移除所有监听器
|
|
204
|
+
*/
|
|
205
|
+
static removeAllListeners() {
|
|
206
|
+
ExpoGaodeMapOfflineModule_1.default.removeAllListeners('onDownloadProgress');
|
|
207
|
+
ExpoGaodeMapOfflineModule_1.default.removeAllListeners('onDownloadComplete');
|
|
208
|
+
ExpoGaodeMapOfflineModule_1.default.removeAllListeners('onDownloadError');
|
|
209
|
+
ExpoGaodeMapOfflineModule_1.default.removeAllListeners('onDownloadPaused');
|
|
210
|
+
ExpoGaodeMapOfflineModule_1.default.removeAllListeners('onDownloadCancelled');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.OfflineMapManager = OfflineMapManager;
|
|
214
|
+
/**
|
|
215
|
+
* 默认导出管理类
|
|
216
|
+
*/
|
|
217
|
+
exports.default = OfflineMapManager;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 位置权限类型
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LocationPermissionType {
|
|
5
|
+
/** 仅前台(使用时) */
|
|
6
|
+
FOREGROUND = "foreground",
|
|
7
|
+
/** 后台位置 */
|
|
8
|
+
BACKGROUND = "background",
|
|
9
|
+
/** 前台+后台 */
|
|
10
|
+
FOREGROUND_AND_BACKGROUND = "foreground_and_background"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 权限工具类
|
|
14
|
+
*
|
|
15
|
+
* 🔔 **重要说明**:
|
|
16
|
+
*
|
|
17
|
+
* 本工具类**不执行实际的权限请求**,仅提供:
|
|
18
|
+
* - 平台检测(Android 14+、iOS 17+)
|
|
19
|
+
* - 权限说明文案(适配新系统特性)
|
|
20
|
+
* - 最佳实践建议
|
|
21
|
+
* - 诊断信息
|
|
22
|
+
*
|
|
23
|
+
* **实际权限请求请使用**:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import ExpoGaodeMapModule from 'expo-gaode-map';
|
|
26
|
+
*
|
|
27
|
+
* // 检查权限
|
|
28
|
+
* const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
29
|
+
*
|
|
30
|
+
* // 请求权限
|
|
31
|
+
* const result = await ExpoGaodeMapModule.requestLocationPermission();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* 本工具类主要用于在请求权限**之前**向用户展示说明文案。
|
|
35
|
+
*/
|
|
36
|
+
export declare class PermissionUtils {
|
|
37
|
+
/**
|
|
38
|
+
* 检查当前平台的系统版本
|
|
39
|
+
*/
|
|
40
|
+
static getSystemInfo(): {
|
|
41
|
+
platform: 'android' | 'ios';
|
|
42
|
+
version: number;
|
|
43
|
+
isAndroid14Plus: boolean;
|
|
44
|
+
isiOS17Plus: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 获取权限说明文案
|
|
48
|
+
*/
|
|
49
|
+
static getPermissionRationale(type: LocationPermissionType): string;
|
|
50
|
+
/**
|
|
51
|
+
* Android 权限说明文案
|
|
52
|
+
*/
|
|
53
|
+
private static getAndroidRationale;
|
|
54
|
+
/**
|
|
55
|
+
* iOS 权限说明文案
|
|
56
|
+
*/
|
|
57
|
+
private static getiOSRationale;
|
|
58
|
+
/**
|
|
59
|
+
* 获取精确位置权限说明(iOS 14+)
|
|
60
|
+
*/
|
|
61
|
+
static getAccuracyRationale(): string;
|
|
62
|
+
/**
|
|
63
|
+
* 获取权限请求的最佳实践建议
|
|
64
|
+
*/
|
|
65
|
+
static getBestPractices(): {
|
|
66
|
+
android14: string[];
|
|
67
|
+
ios17: string[];
|
|
68
|
+
general: string[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 验证 Info.plist 配置(仅 iOS)
|
|
72
|
+
*/
|
|
73
|
+
static validateiOSConfiguration(): {
|
|
74
|
+
valid: boolean;
|
|
75
|
+
missingKeys: string[];
|
|
76
|
+
recommendations: string[];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 检查是否支持后台位置权限
|
|
80
|
+
*/
|
|
81
|
+
static supportsBackgroundLocation(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* 打印权限诊断信息
|
|
84
|
+
*/
|
|
85
|
+
static printDiagnostics(): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 向后兼容的别名
|
|
89
|
+
* @deprecated 请使用 PermissionUtils
|
|
90
|
+
*/
|
|
91
|
+
export declare const PermissionManager: typeof PermissionUtils;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionManager = exports.PermissionUtils = exports.LocationPermissionType = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const PlatformDetector_1 = require("./PlatformDetector");
|
|
6
|
+
/**
|
|
7
|
+
* 位置权限类型
|
|
8
|
+
*/
|
|
9
|
+
var LocationPermissionType;
|
|
10
|
+
(function (LocationPermissionType) {
|
|
11
|
+
/** 仅前台(使用时) */
|
|
12
|
+
LocationPermissionType["FOREGROUND"] = "foreground";
|
|
13
|
+
/** 后台位置 */
|
|
14
|
+
LocationPermissionType["BACKGROUND"] = "background";
|
|
15
|
+
/** 前台+后台 */
|
|
16
|
+
LocationPermissionType["FOREGROUND_AND_BACKGROUND"] = "foreground_and_background";
|
|
17
|
+
})(LocationPermissionType || (exports.LocationPermissionType = LocationPermissionType = {}));
|
|
18
|
+
/**
|
|
19
|
+
* 权限工具类
|
|
20
|
+
*
|
|
21
|
+
* 🔔 **重要说明**:
|
|
22
|
+
*
|
|
23
|
+
* 本工具类**不执行实际的权限请求**,仅提供:
|
|
24
|
+
* - 平台检测(Android 14+、iOS 17+)
|
|
25
|
+
* - 权限说明文案(适配新系统特性)
|
|
26
|
+
* - 最佳实践建议
|
|
27
|
+
* - 诊断信息
|
|
28
|
+
*
|
|
29
|
+
* **实际权限请求请使用**:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import ExpoGaodeMapModule from 'expo-gaode-map';
|
|
32
|
+
*
|
|
33
|
+
* // 检查权限
|
|
34
|
+
* const status = await ExpoGaodeMapModule.checkLocationPermission();
|
|
35
|
+
*
|
|
36
|
+
* // 请求权限
|
|
37
|
+
* const result = await ExpoGaodeMapModule.requestLocationPermission();
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* 本工具类主要用于在请求权限**之前**向用户展示说明文案。
|
|
41
|
+
*/
|
|
42
|
+
class PermissionUtils {
|
|
43
|
+
/**
|
|
44
|
+
* 检查当前平台的系统版本
|
|
45
|
+
*/
|
|
46
|
+
static getSystemInfo() {
|
|
47
|
+
const platform = react_native_1.Platform.OS;
|
|
48
|
+
const systemVersion = PlatformDetector_1.PlatformDetector.getSystemVersion();
|
|
49
|
+
return {
|
|
50
|
+
platform,
|
|
51
|
+
version: systemVersion.version,
|
|
52
|
+
isAndroid14Plus: PlatformDetector_1.PlatformDetector.needsAndroid14Permissions(),
|
|
53
|
+
isiOS17Plus: PlatformDetector_1.PlatformDetector.supportsiOS17Features(),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 获取权限说明文案
|
|
58
|
+
*/
|
|
59
|
+
static getPermissionRationale(type) {
|
|
60
|
+
const { platform, isAndroid14Plus, isiOS17Plus } = this.getSystemInfo();
|
|
61
|
+
if (platform === 'android') {
|
|
62
|
+
return this.getAndroidRationale(type, isAndroid14Plus);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return this.getiOSRationale(type, isiOS17Plus);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Android 权限说明文案
|
|
70
|
+
*/
|
|
71
|
+
static getAndroidRationale(type, isAndroid14) {
|
|
72
|
+
switch (type) {
|
|
73
|
+
case LocationPermissionType.FOREGROUND:
|
|
74
|
+
if (isAndroid14) {
|
|
75
|
+
return `为了在地图上显示您的位置,应用需要访问您的位置信息。
|
|
76
|
+
|
|
77
|
+
您可以选择:
|
|
78
|
+
• 仅在使用应用时允许
|
|
79
|
+
• 每次询问
|
|
80
|
+
|
|
81
|
+
我们不会在后台收集您的位置数据。`;
|
|
82
|
+
}
|
|
83
|
+
return '为了在地图上显示您的位置,应用需要访问您的位置信息。';
|
|
84
|
+
case LocationPermissionType.BACKGROUND:
|
|
85
|
+
if (isAndroid14) {
|
|
86
|
+
return `为了在后台更新您的位置(如导航、轨迹记录),应用需要始终访问位置权限。
|
|
87
|
+
|
|
88
|
+
您可以随时在设置中更改此权限。`;
|
|
89
|
+
}
|
|
90
|
+
return '为了在后台更新您的位置,应用需要始终访问位置权限。';
|
|
91
|
+
case LocationPermissionType.FOREGROUND_AND_BACKGROUND:
|
|
92
|
+
if (isAndroid14) {
|
|
93
|
+
return `应用需要位置权限来提供以下功能:
|
|
94
|
+
• 在地图上显示您的位置(前台)
|
|
95
|
+
• 后台导航和轨迹记录(后台)
|
|
96
|
+
|
|
97
|
+
我们会先请求前台权限,然后再请求后台权限。`;
|
|
98
|
+
}
|
|
99
|
+
return '应用需要位置权限来显示地图位置和后台导航功能。';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* iOS 权限说明文案
|
|
104
|
+
*/
|
|
105
|
+
static getiOSRationale(type, isiOS17) {
|
|
106
|
+
switch (type) {
|
|
107
|
+
case LocationPermissionType.FOREGROUND:
|
|
108
|
+
if (isiOS17) {
|
|
109
|
+
return `为了在地图上显示您的位置,应用需要访问您的位置信息。
|
|
110
|
+
|
|
111
|
+
您可以选择:
|
|
112
|
+
• 使用 App 期间:仅在使用应用时访问位置
|
|
113
|
+
• 一次:仅本次使用时访问位置
|
|
114
|
+
|
|
115
|
+
我们不会在后台收集您的位置数据。`;
|
|
116
|
+
}
|
|
117
|
+
return '为了在地图上显示您的位置,应用需要访问您的位置信息。';
|
|
118
|
+
case LocationPermissionType.BACKGROUND:
|
|
119
|
+
case LocationPermissionType.FOREGROUND_AND_BACKGROUND:
|
|
120
|
+
if (isiOS17) {
|
|
121
|
+
return `为了提供以下功能,应用需要始终访问位置权限:
|
|
122
|
+
• 后台导航和路径规划
|
|
123
|
+
• 轨迹记录
|
|
124
|
+
• 位置提醒
|
|
125
|
+
|
|
126
|
+
您可以随时在设置中更改此权限。`;
|
|
127
|
+
}
|
|
128
|
+
return '为了在后台更新您的位置,应用需要始终访问位置权限。';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 获取精确位置权限说明(iOS 14+)
|
|
133
|
+
*/
|
|
134
|
+
static getAccuracyRationale() {
|
|
135
|
+
const { isiOS17Plus } = this.getSystemInfo();
|
|
136
|
+
if (isiOS17Plus) {
|
|
137
|
+
return `为了提供准确的导航和定位服务,应用需要访问精确位置。
|
|
138
|
+
|
|
139
|
+
选择"模糊位置"可能会导致:
|
|
140
|
+
• 地图定位不准确
|
|
141
|
+
• 导航路线偏差
|
|
142
|
+
• 搜索结果不精确`;
|
|
143
|
+
}
|
|
144
|
+
return '为了提供准确的导航和定位服务,应用需要访问精确位置。';
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 获取权限请求的最佳实践建议
|
|
148
|
+
*/
|
|
149
|
+
static getBestPractices() {
|
|
150
|
+
return {
|
|
151
|
+
android14: [
|
|
152
|
+
'先解释为什么需要权限,再发起请求',
|
|
153
|
+
'前台和后台权限分两步请求',
|
|
154
|
+
'永久拒绝后引导用户到设置页面',
|
|
155
|
+
'提供"仅本次"选项的说明',
|
|
156
|
+
],
|
|
157
|
+
ios17: [
|
|
158
|
+
'在 Info.plist 中提供清晰的权限说明',
|
|
159
|
+
'使用 Privacy Manifest 声明位置访问原因',
|
|
160
|
+
'先请求"使用期间",再请求"始终允许"',
|
|
161
|
+
'支持"仅一次"权限模式',
|
|
162
|
+
],
|
|
163
|
+
general: [
|
|
164
|
+
'在用户需要使用功能时再请求权限',
|
|
165
|
+
'清晰解释权限用途和好处',
|
|
166
|
+
'提供拒绝后的替代方案',
|
|
167
|
+
'尊重用户的权限选择',
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 验证 Info.plist 配置(仅 iOS)
|
|
173
|
+
*/
|
|
174
|
+
static validateiOSConfiguration() {
|
|
175
|
+
if (react_native_1.Platform.OS !== 'ios') {
|
|
176
|
+
return {
|
|
177
|
+
valid: true,
|
|
178
|
+
missingKeys: [],
|
|
179
|
+
recommendations: [],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const recommendations = [];
|
|
183
|
+
const { isiOS17Plus } = this.getSystemInfo();
|
|
184
|
+
if (isiOS17Plus) {
|
|
185
|
+
recommendations.push('建议在 Privacy Manifest (PrivacyInfo.xcprivacy) 中声明位置访问原因', '确保 NSLocationWhenInUseUsageDescription 文案清晰、具体', '如需后台位置,配置 NSLocationAlwaysAndWhenInUseUsageDescription');
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
valid: true,
|
|
189
|
+
missingKeys: [],
|
|
190
|
+
recommendations,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 检查是否支持后台位置权限
|
|
195
|
+
*/
|
|
196
|
+
static supportsBackgroundLocation() {
|
|
197
|
+
const { platform, version } = this.getSystemInfo();
|
|
198
|
+
if (platform === 'android') {
|
|
199
|
+
// Android 10 (API 29) 引入后台位置权限
|
|
200
|
+
return version >= 29;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// iOS 8+ 支持
|
|
204
|
+
return version >= 8;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 打印权限诊断信息
|
|
209
|
+
*/
|
|
210
|
+
static printDiagnostics() {
|
|
211
|
+
const info = this.getSystemInfo();
|
|
212
|
+
console.log('=== 权限管理诊断信息 ===');
|
|
213
|
+
console.log(`平台: ${info.platform}`);
|
|
214
|
+
console.log(`系统版本: ${info.version}`);
|
|
215
|
+
console.log(`Android 14+: ${info.isAndroid14Plus ? '是' : '否'}`);
|
|
216
|
+
console.log(`iOS 17+: ${info.isiOS17Plus ? '是' : '否'}`);
|
|
217
|
+
console.log(`支持后台位置: ${this.supportsBackgroundLocation() ? '是' : '否'}`);
|
|
218
|
+
const practices = this.getBestPractices();
|
|
219
|
+
console.log('\n💡 最佳实践建议:');
|
|
220
|
+
if (info.isAndroid14Plus) {
|
|
221
|
+
console.log('\nAndroid 14+ 特别注意:');
|
|
222
|
+
practices.android14.forEach((tip, index) => {
|
|
223
|
+
console.log(` ${index + 1}. ${tip}`);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (info.isiOS17Plus) {
|
|
227
|
+
console.log('\niOS 17+ 特别注意:');
|
|
228
|
+
practices.ios17.forEach((tip, index) => {
|
|
229
|
+
console.log(` ${index + 1}. ${tip}`);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
console.log('\n通用建议:');
|
|
233
|
+
practices.general.forEach((tip, index) => {
|
|
234
|
+
console.log(` ${index + 1}. ${tip}`);
|
|
235
|
+
});
|
|
236
|
+
if (info.platform === 'ios') {
|
|
237
|
+
const validation = this.validateiOSConfiguration();
|
|
238
|
+
if (validation.recommendations.length > 0) {
|
|
239
|
+
console.log('\niOS 配置建议:');
|
|
240
|
+
validation.recommendations.forEach((rec, index) => {
|
|
241
|
+
console.log(` ${index + 1}. ${rec}`);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
console.log('\n📌 实际权限请求:');
|
|
246
|
+
console.log(' 使用 ExpoGaodeMapModule.checkLocationPermission()');
|
|
247
|
+
console.log(' 使用 ExpoGaodeMapModule.requestLocationPermission()');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.PermissionUtils = PermissionUtils;
|
|
251
|
+
/**
|
|
252
|
+
* 向后兼容的别名
|
|
253
|
+
* @deprecated 请使用 PermissionUtils
|
|
254
|
+
*/
|
|
255
|
+
exports.PermissionManager = PermissionUtils;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 平台检测工具
|
|
3
|
+
* 用于检测设备特性、系统版本等
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 设备类型
|
|
7
|
+
*/
|
|
8
|
+
export declare enum DeviceType {
|
|
9
|
+
PHONE = "phone",
|
|
10
|
+
TABLET = "tablet",
|
|
11
|
+
FOLDABLE = "foldable",
|
|
12
|
+
UNKNOWN = "unknown"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 折叠状态
|
|
16
|
+
*/
|
|
17
|
+
export declare enum FoldState {
|
|
18
|
+
FOLDED = "folded",
|
|
19
|
+
UNFOLDED = "unfolded",
|
|
20
|
+
HALF_FOLDED = "half_folded",
|
|
21
|
+
UNKNOWN = "unknown"
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 设备信息
|
|
25
|
+
*/
|
|
26
|
+
export interface DeviceInfo {
|
|
27
|
+
type: DeviceType;
|
|
28
|
+
isTablet: boolean;
|
|
29
|
+
isFoldable: boolean;
|
|
30
|
+
screenSize: {
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
scale: number;
|
|
34
|
+
fontScale: number;
|
|
35
|
+
};
|
|
36
|
+
aspectRatio: number;
|
|
37
|
+
isLandscape: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 系统版本信息
|
|
41
|
+
*/
|
|
42
|
+
export interface SystemVersion {
|
|
43
|
+
platform: 'ios' | 'android';
|
|
44
|
+
version: number;
|
|
45
|
+
isAndroid14Plus: boolean;
|
|
46
|
+
isIOS17Plus: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 平台检测器类
|
|
50
|
+
*/
|
|
51
|
+
export declare class PlatformDetector {
|
|
52
|
+
private static deviceInfo;
|
|
53
|
+
private static systemVersion;
|
|
54
|
+
/**
|
|
55
|
+
* 获取系统版本信息
|
|
56
|
+
*/
|
|
57
|
+
static getSystemVersion(): SystemVersion;
|
|
58
|
+
/**
|
|
59
|
+
* 获取设备信息
|
|
60
|
+
*/
|
|
61
|
+
static getDeviceInfo(): DeviceInfo;
|
|
62
|
+
/**
|
|
63
|
+
* 检测折叠屏设备
|
|
64
|
+
*/
|
|
65
|
+
private static detectFoldable;
|
|
66
|
+
/**
|
|
67
|
+
* 检测当前折叠状态(需要原生支持)
|
|
68
|
+
*/
|
|
69
|
+
static getFoldState(): FoldState;
|
|
70
|
+
/**
|
|
71
|
+
* 是否为 iPad
|
|
72
|
+
*/
|
|
73
|
+
static isIPad(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 是否支持多任务
|
|
76
|
+
*/
|
|
77
|
+
static supportsMultitasking(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 是否需要 Android 14+ 新权限流程
|
|
80
|
+
*/
|
|
81
|
+
static needsAndroid14Permissions(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* 是否支持 iOS 17+ 新特性
|
|
84
|
+
*/
|
|
85
|
+
static supportsiOS17Features(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* 监听屏幕尺寸变化(折叠屏展开/折叠)
|
|
88
|
+
*/
|
|
89
|
+
static addDimensionChangeListener(callback: (info: DeviceInfo) => void): () => void;
|
|
90
|
+
/**
|
|
91
|
+
* 重置缓存(用于测试或强制刷新)
|
|
92
|
+
*/
|
|
93
|
+
static resetCache(): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 便捷的导出函数
|
|
97
|
+
*/
|
|
98
|
+
export declare const isAndroid14Plus: () => boolean;
|
|
99
|
+
export declare const isiOS17Plus: () => boolean;
|
|
100
|
+
export declare const isTablet: () => boolean;
|
|
101
|
+
export declare const isFoldable: () => boolean;
|
|
102
|
+
export declare const isIPad: () => boolean;
|