react-native-beidou 1.0.7 → 1.1.1

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 (35) hide show
  1. package/BeiDouAIDLTestPage.tsx +505 -19
  2. package/LogManager.ts +284 -0
  3. package/README.md +108 -78
  4. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  5. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  7. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  8. package/android/.idea/caches/deviceStreaming.xml +993 -0
  9. package/android/build.gradle +15 -6
  10. package/android/src/main/AndroidManifest.xml +3 -1
  11. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothModule.java +338 -244
  12. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/BeiDouBluetoothPackage.java +2 -2
  13. package/android/src/main/java/com/fxzs.rnbeidou/BeidouAidlHelper.java +643 -0
  14. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ByteUtil.java +2 -2
  15. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/ChatDBManager.java +46 -46
  16. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/JsonUtil.java +4 -4
  17. package/android/src/main/java/com/fxzs.rnbeidou/LogManager.java +488 -0
  18. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/StringUtils.java +1 -1
  19. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassManager.java +1 -1
  20. package/android/src/main/java/com/{cmcc_rn_module → fxzs.rnbeidou}/view/CompassView.java +2 -2
  21. package/index.ts +233 -79
  22. package/ios/BeiDouBluetoothModule.m +26 -1
  23. package/ios/BeidouBluetooth.framework/BeidouBluetooth +0 -0
  24. package/ios/BeidouBluetooth.framework/FMDB.bundle/Info.plist +0 -0
  25. package/ios/BeidouBluetooth.framework/FMDB.bundle/PrivacyInfo.xcprivacy +14 -0
  26. package/ios/BeidouBluetooth.framework/Headers/BDTLocationService.h +24 -0
  27. package/ios/BeidouBluetooth.framework/Headers/BeidouBluetooth.h +3 -1
  28. package/ios/BeidouBluetooth.framework/Info.plist +0 -0
  29. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
  30. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements-1 +0 -0
  31. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +49 -4
  32. package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
  33. package/package.json +4 -2
  34. package/react-native-beidou.podspec +26 -0
  35. package/react-native.config.js +2 -2
package/LogManager.ts ADDED
@@ -0,0 +1,284 @@
1
+ import React from "react";
2
+ import { NativeModules, Platform } from 'react-native';
3
+
4
+ const { BeiDouBluetoothModule } = NativeModules;
5
+ /**
6
+ * BeiDou SDK 日志管理器
7
+ * 提供统一的日志管理功能,支持Debug/Release模式切换
8
+ */
9
+ export interface LogConfig {
10
+ enableFileLog: boolean; // 是否启用文件日志
11
+ enableConsoleLog: boolean; // 是否启用控制台日志
12
+ maxFileSize: number; // 最大文件大小(MB)
13
+ maxFileCount: number; // 最大文件数量
14
+ encryptionKey?: string; // 加密密钥(可选)
15
+ }
16
+
17
+ export enum LogLevel {
18
+ VERBOSE = 'VERBOSE',
19
+ DEBUG = 'DEBUG',
20
+ INFO = 'INFO',
21
+ WARN = 'WARN',
22
+ ERROR = 'ERROR',
23
+ }
24
+
25
+ /**
26
+ * BeiDou SDK 日志管理器类
27
+ */
28
+ export class BeiDouLogManager {
29
+ private static instance: BeiDouLogManager;
30
+ private isInitialized: boolean = false;
31
+ private currentConfig: LogConfig = {
32
+ enableFileLog: true,
33
+ enableConsoleLog: __DEV__,
34
+ maxFileSize: 10, // 10MB
35
+ maxFileCount: 5,
36
+ };
37
+
38
+ private constructor() {}
39
+
40
+ /**
41
+ * 获取单例实例
42
+ */
43
+ public static getInstance(): BeiDouLogManager {
44
+ if (!BeiDouLogManager.instance) {
45
+ BeiDouLogManager.instance = new BeiDouLogManager();
46
+ }
47
+ return BeiDouLogManager.instance;
48
+ }
49
+
50
+ /**
51
+ * 初始化日志管理器
52
+ * @param config 日志配置
53
+ */
54
+ public async initialize(config?: Partial<LogConfig>): Promise<void> {
55
+ if (this.isInitialized) {
56
+ return;
57
+ }
58
+
59
+ if (config) {
60
+ this.currentConfig = { ...this.currentConfig, ...config };
61
+ }
62
+
63
+ try {
64
+ if (Platform.OS === 'android') {
65
+ await BeiDouBluetoothModule.configureLogger(
66
+ this.currentConfig.enableFileLog,
67
+ this.currentConfig.enableConsoleLog,
68
+ this.currentConfig.maxFileSize,
69
+ this.currentConfig.maxFileCount,
70
+ this.currentConfig.encryptionKey || null
71
+ );
72
+ }
73
+
74
+ this.isInitialized = true;
75
+ this.info('BeiDouLogManager', 'LogManager initialized successfully');
76
+ } catch (error) {
77
+ console.error('Failed to initialize BeiDou LogManager:', error);
78
+ throw error;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 更新日志配置
84
+ * @param config 新的配置
85
+ */
86
+ public async updateConfig(config: Partial<LogConfig>): Promise<void> {
87
+ this.currentConfig = { ...this.currentConfig, ...config };
88
+
89
+ try {
90
+ if (Platform.OS === 'android') {
91
+ await BeiDouBluetoothModule.configureLogger(
92
+ this.currentConfig.enableFileLog,
93
+ this.currentConfig.enableConsoleLog,
94
+ this.currentConfig.maxFileSize,
95
+ this.currentConfig.maxFileCount,
96
+ this.currentConfig.encryptionKey || null
97
+ );
98
+ }
99
+
100
+ this.info('BeiDouLogManager', 'LogManager config updated');
101
+ } catch (error) {
102
+ console.error('Failed to update BeiDou LogManager config:', error);
103
+ throw error;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Verbose日志
109
+ */
110
+ public async verbose(tag: string, message: string): Promise<void> {
111
+ return this.writeLog(LogLevel.VERBOSE, tag, message);
112
+ }
113
+
114
+ /**
115
+ * Debug日志
116
+ */
117
+ public async debug(tag: string, message: string): Promise<void> {
118
+ return this.writeLog(LogLevel.DEBUG, tag, message);
119
+ }
120
+
121
+ /**
122
+ * Info日志
123
+ */
124
+ public async info(tag: string, message: string): Promise<void> {
125
+ return this.writeLog(LogLevel.INFO, tag, message);
126
+ }
127
+
128
+ /**
129
+ * Warning日志
130
+ */
131
+ public async warn(tag: string, message: string): Promise<void> {
132
+ return this.writeLog(LogLevel.WARN, tag, message);
133
+ }
134
+
135
+ /**
136
+ * Error日志
137
+ */
138
+ public async error(tag: string, message: string): Promise<void> {
139
+ return this.writeLog(LogLevel.ERROR, tag, message);
140
+ }
141
+
142
+ /**
143
+ * 写入日志
144
+ * @param level 日志级别
145
+ * @param tag 标签
146
+ * @param message 消息
147
+ */
148
+ private async writeLog(level: LogLevel, tag: string, message: string): Promise<void> {
149
+ try {
150
+ // 控制台输出(根据配置)
151
+ if (this.currentConfig.enableConsoleLog) {
152
+ const timestamp = new Date().toISOString();
153
+ const logMessage = `[${timestamp}] [${level}] [${tag}] ${message}`;
154
+
155
+ switch (level) {
156
+ case LogLevel.VERBOSE:
157
+ case LogLevel.DEBUG:
158
+ console.log(logMessage);
159
+ break;
160
+ case LogLevel.INFO:
161
+ console.info(logMessage);
162
+ break;
163
+ case LogLevel.WARN:
164
+ console.warn(logMessage);
165
+ break;
166
+ case LogLevel.ERROR:
167
+ console.error(logMessage);
168
+ break;
169
+ }
170
+ }
171
+
172
+ // 文件输出(通过原生模块)
173
+ if (Platform.OS === 'android' && this.currentConfig.enableFileLog) {
174
+ await BeiDouBluetoothModule.writeLog(level, tag, message);
175
+ }
176
+ } catch (error) {
177
+ // 日志写入失败时使用console作为备选
178
+ console.error('Failed to write log:', error);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * 获取日志统计信息
184
+ */
185
+ public async getLogStats(): Promise<string> {
186
+ try {
187
+ if (Platform.OS === 'android') {
188
+ return await BeiDouBluetoothModule.getLogStats();
189
+ }
190
+ return 'Log stats not available on this platform';
191
+ } catch (error) {
192
+ console.error('Failed to get log stats:', error);
193
+ return 'Failed to get log stats: ' + error;
194
+ }
195
+ }
196
+
197
+ /**
198
+ * 清空所有日志文件
199
+ */
200
+ public async clearAllLogs(): Promise<void> {
201
+ try {
202
+ if (Platform.OS === 'android') {
203
+ await BeiDouBluetoothModule.clearAllLogs();
204
+ }
205
+ this.info('BeiDouLogManager', 'All logs cleared');
206
+ } catch (error) {
207
+ console.error('Failed to clear logs:', error);
208
+ throw error;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * 获取当前配置
214
+ */
215
+ public getConfig(): LogConfig {
216
+ return { ...this.currentConfig };
217
+ }
218
+
219
+ /**
220
+ * 检查是否已初始化
221
+ */
222
+ public isReady(): boolean {
223
+ return this.isInitialized;
224
+ }
225
+ }
226
+
227
+ // 导出单例实例
228
+ export const BeiDouLogger = BeiDouLogManager.getInstance();
229
+
230
+ // 导出便捷方法
231
+ export const logVerbose = (tag: string, message: string) => BeiDouLogger.verbose(tag, message);
232
+ export const logDebug = (tag: string, message: string) => BeiDouLogger.debug(tag, message);
233
+ export const logInfo = (tag: string, message: string) => BeiDouLogger.info(tag, message);
234
+ export const logWarn = (tag: string, message: string) => BeiDouLogger.warn(tag, message);
235
+ export const logError = (tag: string, message: string) => BeiDouLogger.error(tag, message);
236
+
237
+ /**
238
+ * 全局日志拦截器
239
+ * 在Release模式下拦截console日志并重定向到文件
240
+ */
241
+ export const setupGlobalLogInterception = () => {
242
+ if (!__DEV__) {
243
+ // 保存原始console方法
244
+ const originalConsole = {
245
+ log: console.log,
246
+ info: console.info,
247
+ warn: console.warn,
248
+ error: console.error,
249
+ debug: console.debug,
250
+ };
251
+
252
+ // 重写console方法
253
+ console.log = (...args) => {
254
+ BeiDouLogger.info('Console', args.join(' '));
255
+ };
256
+
257
+ console.info = (...args) => {
258
+ BeiDouLogger.info('Console', args.join(' '));
259
+ };
260
+
261
+ console.warn = (...args) => {
262
+ BeiDouLogger.warn('Console', args.join(' '));
263
+ };
264
+
265
+ console.error = (...args) => {
266
+ BeiDouLogger.error('Console', args.join(' '));
267
+ };
268
+
269
+ console.debug = (...args) => {
270
+ BeiDouLogger.debug('Console', args.join(' '));
271
+ };
272
+
273
+ // 提供恢复原始console的方法(用于调试)
274
+ (global as any).__restoreConsole = () => {
275
+ Object.assign(console, originalConsole);
276
+ };
277
+ }
278
+ };
279
+
280
+ export default BeiDouLogManager;
281
+
282
+
283
+
284
+
package/README.md CHANGED
@@ -1,78 +1,108 @@
1
- # React Native 北斗蓝牙 SDK(react-native-beidou)
2
-
3
- ## 安装
4
-
5
- ```bash
6
- yarn add react-native-beidou
7
- ```
8
-
9
- ### iOS
10
-
11
- 在 `ios/Podfile` 中确保加入:
12
-
13
- ```ruby
14
- pod 'react-native-beidou', :path => '../node_modules/react-native-beidou'
15
- ```
16
-
17
- 执行:
18
-
19
- ```bash
20
- cd ios && pod install
21
- ```
22
-
23
- 注意:
24
- - 本库通过 `vendored_frameworks` 引入 `BeidouBluetooth.framework`,无需额外拷贝。
25
- - 最低平台版本需满足 iOS 15.6(来自 `react-native-beidou.podspec`)。
26
-
27
- ### Android
28
-
29
- 采用 RN Autolinking,无需手动修改。若出现无法自动链接,可检查本库提供的 `react-native.config.js`:
30
-
31
- ```js
32
- packageImportPath: "import com.cmcc_rn_module.BeiDouBluetoothPackage;",
33
- packageInstance: "new com.cmcc_rn_module.BeiDouBluetoothPackage()"
34
- ```
35
-
36
- 库内已包含 `android/libs/bluetooth-sdk.aar`,通常无需额外配置。
37
-
38
- ---
39
-
40
- ## 权限与配置
41
-
42
- ### Android 权限(必配)
43
-
44
- 在宿主应用 `android/app/src/main/AndroidManifest.xml` 中添加(按系统版本动态申请):
45
-
46
- ```xml
47
- <!-- Android 12+ -->
48
- <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
49
- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
50
-
51
- <!-- Android 6.0+ 扫描需要位置权限 -->
52
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
53
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
54
-
55
- <!-- WiFi 名称读取(可选) -->
56
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
57
-
58
- <!-- 建议配置,声明低功耗蓝牙能力 -->
59
- <uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
60
- ```
61
-
62
- 混淆(如启用 ProGuard/R8)建议保留:
63
-
64
- ```proguard
65
- -keep class com.beidou.bluetooth.** { *; }
66
- -keep class com.cmcc_rn_module.** { *; }
67
- ```
68
-
69
- ### iOS 权限(Info.plist)
70
-
71
- 根据实际需要添加:
72
-
73
- ```xml
74
- <key>NSBluetoothAlwaysUsageDescription</key>
75
- <string>需要使用蓝牙与北斗终端通信</string>
76
- <key>NSLocationWhenInUseUsageDescription</key>
77
- <string>用于蓝牙扫描或获取WiFi信息</string>
78
- ```
1
+ # React Native 北斗蓝牙 SDK(react-native-beidou)
2
+
3
+ ## 安装
4
+
5
+ ```bash
6
+ yarn add react-native-beidou
7
+ ```
8
+
9
+ ### iOS
10
+
11
+ 在 `ios/Podfile` 中确保加入:
12
+
13
+ ```ruby
14
+ pod 'react-native-beidou', :path => '../node_modules/react-native-beidou'
15
+ ```
16
+
17
+ 执行:
18
+
19
+ ```bash
20
+ cd ios && pod install
21
+ ```
22
+
23
+ ---
24
+
25
+ ## 权限与配置
26
+
27
+ ### Android 权限
28
+
29
+
30
+ ```xml
31
+ <!-- Android 12+ -->
32
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
33
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
34
+
35
+ <!-- Android 6.0+ 扫描需要位置权限 -->
36
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
37
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
38
+
39
+ <!-- WiFi 名称读取(可选) -->
40
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
41
+
42
+ <!-- 建议配置,声明低功耗蓝牙能力 -->
43
+ <uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
44
+ ```
45
+
46
+
47
+ ### iOS 权限
48
+
49
+
50
+ ```xml
51
+ <key>NSBluetoothAlwaysUsageDescription</key>
52
+ <string>需要使用蓝牙与北斗终端通信</string>
53
+ <key>NSLocationWhenInUseUsageDescription</key>
54
+ <string>用于蓝牙扫描或获取WiFi信息</string>
55
+ ```
56
+
57
+
58
+ ### 北斗小程序 RN 用到的所有库
59
+
60
+ ```
61
+ "dependencies": {
62
+ "@ant-design/icons-react-native": "2.3.2",
63
+ "@ant-design/react-native": "5.3.1",
64
+ "@kafudev/react-native-vconsole": "^0.1.11",
65
+ "@react-native-async-storage/async-storage": "2.0.0",
66
+ "@react-navigation/bottom-tabs": "^6.3.1",
67
+ "@react-navigation/native": "^6.0.10",
68
+ "@react-navigation/native-stack": "^6.7.0",
69
+ "@react-navigation/stack": "^6.2.1",
70
+ "@reduxjs/toolkit": "^1.8.2",
71
+ "buffer": "^6.0.3",
72
+ "cmcc-bridge-module": "file:library/cmcc-bridge-module-1.0.0.tgz",
73
+ "crypto-es": "2.1.0",
74
+ "crypto-js": "4.2.0",
75
+ "dayjs": "1.11.13",
76
+ "lodash": "4.17.21",
77
+ "node-forge": "^1.3.1",
78
+ "react": "17.0.2",
79
+ "react-native": "0.68.7",
80
+ "react-native-axios": "0.17.1",
81
+ "react-native-beidou": "1.0.8",
82
+ "react-native-contacts": "^8.0.5",
83
+ "react-native-gesture-handler": "2.14.1",
84
+ "react-native-haptic-feedback": "1.14.0",
85
+ "react-native-image-zoom-viewer": "3.0.1",
86
+ "react-native-intersection-observer": "0.2.0",
87
+ "react-native-linear-gradient": "2.8.3",
88
+ "react-native-media-console": "2.2.4",
89
+ "react-native-orientation-locker": "1.4.0",
90
+ "react-native-reanimated": "2.17.0",
91
+ "react-native-reanimated-carousel": "3.5.1",
92
+ "react-native-render-html": "6.3.4",
93
+ "react-native-root-toast": "^3.5.1",
94
+ "react-native-safe-area-context": "4.5.0",
95
+ "react-native-signature-canvas": "4.7.2",
96
+ "react-native-storage": "1.0.1",
97
+ "react-native-svg": "12.5.1",
98
+ "react-native-video": "5.2.1",
99
+ "react-native-view-shot": "3.8.0",
100
+ "react-native-webview": "13.10.2",
101
+ "react-redux": "^8.0.2",
102
+ "redux-persist": "^6.0.0",
103
+ "supercluster": "7.1.5",
104
+ "rn-keychain": "1.0.1",
105
+ "zustand": "4.5.5"
106
+ },
107
+
108
+ ```
@@ -1,2 +1,2 @@
1
- #Fri Oct 24 11:21:51 CST 2025
2
- gradle.version=8.10
1
+ #Mon Nov 17 14:26:40 CST 2025
2
+ gradle.version=8.9