react-native-beidou 1.0.4 → 1.0.6

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.
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { requireNativeComponent, ViewStyle } from 'react-native';
3
+
4
+ type CompassProps = {
5
+ style?: ViewStyle;
6
+ onHeadingChange?: (event: { nativeEvent: { radians: number; degrees: number } }) => void;
7
+ };
8
+
9
+ const CompassNativeView = requireNativeComponent<CompassProps>('CompassView');
10
+
11
+ const Compass: React.FC<CompassProps> = (props) => {
12
+ return <CompassNativeView {...props} />;
13
+ };
14
+
15
+ export default Compass;
package/Compass.tsx ADDED
@@ -0,0 +1,6 @@
1
+ // Compass.tsx
2
+ import { Platform } from 'react-native';
3
+ import CompassIOS from './Compass.ios';
4
+ import CompassAndroid from './Compass.android';
5
+
6
+ export default Platform.OS === 'ios' ? CompassIOS : CompassAndroid;
package/README.md CHANGED
@@ -1,154 +1,78 @@
1
- # RN 项目
1
+ # React Native 北斗蓝牙 SDK(react-native-beidou)
2
2
 
3
- 开发分支: h5-dev
3
+ ## 安装
4
4
 
5
- 环境搭建:https://reactnative.cn/docs/environment-setup
6
-
7
- react 中文网:https://www.php.cn/doc/react/index.html 学习函数组件、类组件可以先不学
8
-
9
- es6 教程:https://www.runoob.com/w3cnote
10
-
11
- useMock:https://www.usemock.com/login >>>>>>>>>在【useMock 协作项目】
12
-
13
- UI 库: https://rn.mobile.ant.design/docs/react/introduce-cn 版本:`5.2.3`
14
-
15
- 开发工具: vscode, 插件:eslint(自动格式化)、react-native-snippets(代码提示)
16
-
17
- .vscode 可以扩展自定义模板,现有创建组件模板 rnc 指令
18
-
19
- `node: v18.17.1`
20
- `yarn: 1.22.22`
21
-
22
- 新建页面、组件规范: pages、components、assets 以页面维度划分
23
-
24
- # 安卓 gif 与 webp 支持
5
+ ```bash
6
+ yarn add react-native-beidou
7
+ ```
25
8
 
26
- 项目的 android 目录输入
27
- cd android
28
- .\gradlew app:dependencies --configuration releaseRuntimeClasspath
9
+ ### iOS
29
10
 
30
- # 常用脚本
11
+ `ios/Podfile` 中确保加入:
31
12
 
32
- ```
33
- "mock": "nodemon ./mock/mock.js",
34
- "android": "gulp dev-android",
35
- "ios": "gulp dev-ios",
36
- "start": "gulp dev-start",
37
- "test": "jest",
38
- "build": "gulp default",
39
- "upload": "gulp upload",
40
- "build:dll-custom": "gulp build-custom",
41
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
42
- "bundle:analysis": "react-native-bundle-visualizer"
13
+ ```ruby
14
+ pod 'react-native-beidou', :path => '../node_modules/react-native-beidou'
43
15
  ```
44
16
 
45
- 例如
17
+ 执行:
46
18
 
47
- ```
48
- 开发启动命令
49
- yarn android --pageName=页面名称
50
- 页面名称:src/pages下的页面入口文件名(不带后缀)
51
-
52
-
53
- 使用metro配置自定义拆包:
54
- 业务包(页面级别)可以直接使用页面名字,如Demo。打包配置走metro.main.config.js;
55
- 非业务包(包括node_modules里的第三方插件、utils自定义公共方法)需要在custom.config.js里配置。打包配置走metro.common.config.js
56
- 输出:bundle/(ios|android)-${pageName}
57
- splitCache: 打包信息缓存,目前之缓存非业务包信息,带_origin为路径信息缓存,不带的是打包id缓存
58
- yarn build:dll-custom --pageName=dll
59
- yarn build:dll-custom --pageName=utils
60
- yarn build:dll-custom --pageName=Demo
61
-
62
- 添加参数:
63
- --pageName=<页面名称> 指定要打包的页面名称(必填)
64
- --ios 只打iOS包,不打Android包
65
- --android 只打Android包,不打iOS包
66
- --sourceMap 生成sourcemap文件,用于错误堆栈符号化
67
-
68
- 示例:
69
- yarn build:dll-custom --pageName=Demo1 --ios --sourceMap
19
+ ```bash
20
+ cd ios && pod install
70
21
  ```
71
22
 
72
- # js 能力相关的
23
+ 注意:
24
+ - 本库通过 `vendored_frameworks` 引入 `BeidouBluetooth.framework`,无需额外拷贝。
25
+ - 最低平台版本需满足 iOS 15.6(来自 `react-native-beidou.podspec`)。
73
26
 
74
- 1.如果依赖 js 能力的数据,可以用 async await
27
+ ### Android
75
28
 
76
- 2.不依赖的话,用.then 的方式或者不需要接收的方式,防止阻塞后面代码执行
29
+ 采用 RN Autolinking,无需手动修改。若出现无法自动链接,可检查本库提供的 `react-native.config.js`:
77
30
 
31
+ ```js
32
+ packageImportPath: "import com.cmcc_rn_module.BeiDouBluetoothPackage;",
33
+ packageInstance: "new com.cmcc_rn_module.BeiDouBluetoothPackage()"
78
34
  ```
79
- // js能力调用方法
80
- try {
81
- const data = await callNativeMethod({
82
- businessName: 'userStatus',
83
- debug: false,
84
- ...剩余参数(不要传success和error),
85
- });
86
- // succes回调
87
- console.log('%c Line:141 🍰 data', 'color:#7f2b82', data);
88
- } catch (error) {
89
- // error回调
90
- console.log('%c Line:148 🍰 error', 'color:#b03734', error);
91
- }
92
-
93
- // 参考商城写法
94
- // useInfo 更新调用接口
95
- useEffect(() => {
96
- !!userInfo && getData();
97
- }, [userInfo]);
98
-
99
- useEffect(() => {
100
- // 强登isForceLogin
101
- loginInfo({isForceLogin: false}).then((res: any) => {
102
- setUserInfo(res);
103
- });
104
- }, []);
105
- ```
106
-
107
- # 开发在线调试
108
-
109
- 1.yarn build
110
-
111
- 2.yarn upload 上传 jsbundle 到服务器
112
35
 
113
- 3.客户端设置页输入 jsbundle 地址,开启调试模式
36
+ 库内已包含 `android/libs/bluetooth-sdk.aar`,通常无需额外配置。
114
37
 
115
- # 本地 mock
38
+ ---
116
39
 
117
- 启动命令 `yarn mock`
40
+ ## 权限与配置
118
41
 
119
- 根据 data 里的 json 文件名自动创建路由,修改文件自动启动服务
42
+ ### Android 权限(必配)
120
43
 
121
- 例如
44
+ 在宿主应用 `android/app/src/main/AndroidManifest.xml` 中添加(按系统版本动态申请):
122
45
 
123
- users.json => http://localhost:3000/api/users
46
+ ```xml
47
+ <!-- Android 12+ -->
48
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
49
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
124
50
 
125
- # 注意事项
51
+ <!-- Android 6.0+ 扫描需要位置权限 -->
52
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
53
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
126
54
 
127
- 1. 定时器相关的,都要有清除逻辑,不然会报内存泄漏, 接收的地方都用 ref
128
- 2. 页面如果要用不涉及更新的全局变量,不要写在组件外面,都用 ref
129
- 3. `react-native-swiper`组件废弃,新页面采用`react-native-reanimated-carousel`
55
+ <!-- WiFi 名称读取(可选) -->
56
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
130
57
 
131
- # 符号化错误堆栈(Symbolication)
132
-
133
- 当React Native应用崩溃时,错误堆栈通常包含混淆后的代码位置,使调试变得困难。使用symbolicate命令可以将这些位置转换为源代码中的实际位置。
58
+ <!-- 建议配置,声明低功耗蓝牙能力 -->
59
+ <uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
60
+ ```
134
61
 
135
- 使用方法: 文件路径相对于工程根目录
62
+ 混淆(如启用 ProGuard/R8)建议保留:
136
63
 
137
- ```
138
- yarn symbolicate --sourcemap=<sourcemap文件路径> --stack=<错误堆栈文件路径>
64
+ ```proguard
65
+ -keep class com.beidou.bluetooth.** { *; }
66
+ -keep class com.cmcc_rn_module.** { *; }
139
67
  ```
140
68
 
141
- 参数说明:
142
- - `--sourcemap`:指定sourcemap文件的路径,例如:`CT00010.jsbundle.map`。该文件是在打包时生成的,包含源代码和打包后代码的映射关系。
143
- - `--stack`:指定包含错误堆栈信息的文本文件路径,例如:`error.txt`。该文件包含应用崩溃时的错误堆栈信息。
69
+ ### iOS 权限(Info.plist)
144
70
 
145
- 注意事项:
146
- - 打包时需要添加`--sourceMap`参数才会生成sourcemap文件,例如:`yarn build --sourceMap`或`yarn build:dll-custom --pageName=Demo --sourceMap`
147
- - 符号化过程使用`metro-symbolicate`工具,会自动将混淆后的代码位置映射回源代码位置
71
+ 根据实际需要添加:
148
72
 
149
- 示例:
73
+ ```xml
74
+ <key>NSBluetoothAlwaysUsageDescription</key>
75
+ <string>需要使用蓝牙与北斗终端通信</string>
76
+ <key>NSLocationWhenInUseUsageDescription</key>
77
+ <string>用于蓝牙扫描或获取WiFi信息</string>
150
78
  ```
151
- yarn symbolicate --sourcemap=CT00010.jsbundle.map --stack=error.txt
152
- ```
153
-
154
- 执行后,将输出符号化后的错误堆栈信息,帮助开发者快速定位问题所在位置。
@@ -1,2 +1,2 @@
1
- #Tue Sep 16 15:41:38 CST 2025
2
- gradle.version=8.9
1
+ #Fri Oct 24 11:21:51 CST 2025
2
+ gradle.version=8.10
@@ -143,7 +143,7 @@ public class BeiDouBluetoothModule extends ReactContextBaseJavaModule {
143
143
 
144
144
  // 开始扫描蓝牙设备
145
145
  @ReactMethod
146
- public void startScanForService() {
146
+ public void startScanForService(Callback callback) {
147
147
  BluetoothSDK instance = BluetoothSDK.getInstance(reactContext);
148
148
  Log.d("BluetoothSDK", "MyModule-> 开始扫描");
149
149
  instance.startScan();
package/index.ts CHANGED
@@ -80,7 +80,7 @@ export interface MessageInfo {
80
80
  interface BeiDouBluetoothModuleType {
81
81
  // 原有蓝牙相关方法
82
82
  getAllConversations(): Promise<string>; // 更新为Promise版本
83
- startScanForService(): void;
83
+ startScanForService(callback: (res: number) => void): void;
84
84
  stopScanning(): void;
85
85
  getDiscoveredDevices(): Promise<string>; // JSON string of BlueDeviceInfoEntity[]
86
86
  connectToDeviceFromCloudDeviceNO(deviceNO: string, a: number): Promise<'ok' | 'fail'>;
@@ -89,7 +89,7 @@ interface BeiDouBluetoothModuleType {
89
89
  shouldShowBlueToothPermissionRationale(params: string, callback: (status: BluetoothPermissionRationaleStatus) => void): void;
90
90
  initializeBluetooth(callback: (status: BluetoothStatus) => void): void;
91
91
  generateRandom16BytesString(): string;
92
- writeData(randomString: string, deviceNo: string, command: number, attrType: number, encrypt: boolean, callback: (result: number) => void): void;
92
+ writeData(randomString: string, deviceNo: string, command: number, attrType: number, callback: (result: number) => void): void;
93
93
 
94
94
  // 新增的iOS兼容方法
95
95
  writeInfo(base64Payload: string | null, deviceNO: string, command: number, opCode: number, attrType: number, encrypted: boolean): Promise<WriteInfoResponse>;
@@ -355,8 +355,8 @@ export const setBeiDouBLEKey = async (bleKey: string): Promise<boolean> => {
355
355
  export const BeiDouModule = {
356
356
  // 蓝牙相关
357
357
  bluetooth: {
358
- startScan: () => BeiDouBluetoothModule.startScanForService(),
359
- startScanIOS: (callback: (result: number) => void) => BeiDouBluetoothModule.startScanForService(callback),
358
+ // startScan: () => BeiDouBluetoothModule.startScanForService(),
359
+ startScan: (callback: (result: number) => void) => BeiDouBluetoothModule.startScanForService(callback),
360
360
  stopScan: () => BeiDouBluetoothModule.stopScanning(),
361
361
  getDevices: getDiscoveredDevicesArray,
362
362
  connect: (deviceNo: string) => BeiDouBluetoothModule.connectToDeviceFromCloudDeviceNO(deviceNo, 0),
@@ -152,7 +152,7 @@ RCT_EXPORT_METHOD(writeData:(NSString *)base64String
152
152
  deviceId:deviceNO
153
153
  command:commandValue
154
154
  opcode:0
155
- attrType:attrType
155
+ attrType:0
156
156
  encrypted:isEncrypted
157
157
  callback:^(NSInteger result) {
158
158
  if (result == 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-beidou",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "A React Native module for BeiDou Bluetooth communication.",
5
5
  "main": "index.ts",
6
6
  "types": "index.ts",
@@ -10,6 +10,8 @@
10
10
  "ios",
11
11
  "index.ts",
12
12
  "Compass.android.tsx",
13
+ "Compass.ios.tsx",
14
+ "Compass.tsx",
13
15
  "react-native.config.js",
14
16
  "BeiDouAIDLTestPage.tsx",
15
17
  "TestPage.ts"