react-native-beidou 1.0.3 → 1.0.5
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/BeiDouAIDLTestPage.tsx +7 -7
- package/Compass.android.tsx +20 -0
- package/Compass.ios.tsx +15 -0
- package/Compass.tsx +6 -0
- package/README.md +48 -124
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.idea/AndroidProjectSystem.xml +6 -0
- package/android/.idea/gradle.xml +13 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +3 -0
- package/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/java/com/cmcc_rn_module/BeiDouBluetoothModule.java +343 -101
- package/android/src/main/java/com/cmcc_rn_module/BeiDouBluetoothPackage.java +4 -1
- package/android/src/main/java/com/cmcc_rn_module/ChatDBManager.java +306 -0
- package/android/src/main/java/com/cmcc_rn_module/JsonUtil.java +113 -7
- package/android/src/main/java/com/cmcc_rn_module/view/CompassManager.java +41 -0
- package/android/src/main/java/com/cmcc_rn_module/view/CompassView.java +277 -0
- package/android/src/main/libs/bluetooth-sdk.aar +0 -0
- package/index.ts +188 -10
- package/ios/BDTCompassViewManager.h +15 -0
- package/ios/BDTCompassViewManager.m +24 -0
- package/ios/BeiDouBluetoothModule.h +20 -0
- package/ios/BeiDouBluetoothModule.m +424 -0
- package/ios/BeidouBluetooth.framework/BeidouBluetooth +0 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTBluetoothManager.h +76 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTChatDBManager.h +41 -0
- package/ios/BeidouBluetooth.framework/Headers/BDTDataPacketBuilder.h +62 -0
- package/ios/BeidouBluetooth.framework/Headers/BeidouBluetooth.h +21 -0
- package/ios/BeidouBluetooth.framework/Info.plist +0 -0
- package/ios/BeidouBluetooth.framework/Modules/module.modulemap +6 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeDirectory +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeRequirements-1 +0 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeResources +177 -0
- package/ios/BeidouBluetooth.framework/_CodeSignature/CodeSignature +0 -0
- package/ios/CompassView.h +20 -0
- package/ios/CompassView.m +201 -0
- package/package.json +4 -1
- package/android/.gradle/8.8/checksums/checksums.lock +0 -0
- package/android/.gradle/8.8/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.8/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.8/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.8/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.8/gc.properties +0 -0
- package/ios/Podfile +0 -79
- package/ios/build_sdk.sh +0 -30
- package/ios/cmcc_rn_module/AppDelegate.h +0 -8
- package/ios/cmcc_rn_module/AppDelegate.mm +0 -108
- package/ios/cmcc_rn_module/CMCCAssetsLoaderModule.h +0 -17
- package/ios/cmcc_rn_module/CMCCAssetsLoaderModule.m +0 -38
- package/ios/cmcc_rn_module/Images.xcassets/AppIcon.appiconset/Contents.json +0 -53
- package/ios/cmcc_rn_module/Images.xcassets/Contents.json +0 -6
- package/ios/cmcc_rn_module/Info.plist +0 -62
- package/ios/cmcc_rn_module/LaunchScreen.storyboard +0 -47
- package/ios/cmcc_rn_module/main.m +0 -10
- package/ios/cmcc_rn_module.xcodeproj/project.pbxproj +0 -708
- package/ios/cmcc_rn_module.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/cmcc_rn_module.xcodeproj/xcshareddata/xcschemes/cmcc_rn_module.xcscheme +0 -88
- package/ios/cmcc_rn_module.xcworkspace/contents.xcworkspacedata +0 -10
- package/ios/cmcc_rn_module.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/cmcc_rn_moduleTests/Info.plist +0 -24
- package/ios/cmcc_rn_moduleTests/cmcc_rn_moduleTests.m +0 -66
- package/ios/reset_env.sh +0 -24
- package/ios/scripts/RNReanimated.podspec +0 -90
- package/ios/scripts/generate_dynamic_pod.rb +0 -166
- package/ios/scripts/native_modules_dy.rb +0 -317
- package/ios/scripts/react_native_pods_dy.rb +0 -773
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BeiDouBluetoothModule.m
|
|
3
|
+
// IntegrateSingleIecmIot
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/9/4.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import "BeiDouBluetoothModule.h"
|
|
9
|
+
#import <BeidouBluetooth/BeidouBluetooth.h>
|
|
10
|
+
#import <React/RCTRootView.h>
|
|
11
|
+
#import "BDTChatDBManager.h"
|
|
12
|
+
|
|
13
|
+
@interface BeiDouBluetoothModule () <BDTBluetoothMonitor>
|
|
14
|
+
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
@implementation BeiDouBluetoothModule
|
|
18
|
+
|
|
19
|
+
RCT_EXPORT_MODULE();
|
|
20
|
+
|
|
21
|
+
+ (BeiDouBluetoothModule *)defaultModule{
|
|
22
|
+
static BeiDouBluetoothModule *RNBridgeReceiver_default = nil;
|
|
23
|
+
static dispatch_once_t predicate;
|
|
24
|
+
dispatch_once(&predicate, ^{
|
|
25
|
+
RNBridgeReceiver_default = [[self alloc] init];
|
|
26
|
+
});
|
|
27
|
+
return RNBridgeReceiver_default;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
- (instancetype)init {
|
|
31
|
+
self = [super init];
|
|
32
|
+
if (self) {
|
|
33
|
+
|
|
34
|
+
[BDTBluetoothManager shared].delegate = self;
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
return self;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
-(NSArray<NSString *> *)supportedEvents{
|
|
41
|
+
return @[@"suncthing_success",@"nasConnectFailed",@"exitTCN100",@"screenshotNotice",@"noticeUploadSpeed",@"etsNoticeUploadComplete",@"listenUpdateNotice",@"listenBluetoolth",@"listenNetStatus"];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/// 开始扫描
|
|
46
|
+
/// - Parameter param: 当系统或者应用蓝牙开关关闭时会触发此回调 3:用户拒绝授权 4:系统蓝牙开关关闭
|
|
47
|
+
RCT_EXPORT_METHOD(startScanForService:(RCTResponseSenderBlock)callBack) {
|
|
48
|
+
[[BDTBluetoothManager shared] startScanningForServices:nil callBack:^(NSInteger statu) {
|
|
49
|
+
callBack(@[@(statu)]);
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// 结束扫描
|
|
54
|
+
RCT_EXPORT_METHOD(stopScanning) {
|
|
55
|
+
[[BDTBluetoothManager shared] stopScanning];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// 获取扫描到的蓝牙设备列表
|
|
59
|
+
/// - Parameter resolve: 设备列表信息回调 note:返回的类型是包含设备信息的数组的json字符串
|
|
60
|
+
/// - Parameter reject: 异常失败回调
|
|
61
|
+
RCT_EXPORT_METHOD(getDiscoveredDevices:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
62
|
+
|
|
63
|
+
@try {
|
|
64
|
+
NSArray<BDTBluetoothDevice *> * deviceArr = [[BDTBluetoothManager shared] getDiscoveredDevices];
|
|
65
|
+
NSMutableArray *deviceArray = [NSMutableArray array];
|
|
66
|
+
for (BDTBluetoothDevice *device in deviceArr) {
|
|
67
|
+
NSMutableDictionary *infoDic = [NSMutableDictionary dictionary];
|
|
68
|
+
infoDic[@"name"] = device.name;
|
|
69
|
+
infoDic[@"uuid"] = device.identifier.UUIDString;
|
|
70
|
+
infoDic[@"rssi"] = [NSNumber numberWithInteger:device.rssi];
|
|
71
|
+
infoDic[@"venderID"] = device.venderID;
|
|
72
|
+
infoDic[@"productID"] = device.productID;
|
|
73
|
+
infoDic[@"deviceNO"] = device.deviceNO;
|
|
74
|
+
[deviceArray addObject:infoDic];
|
|
75
|
+
}
|
|
76
|
+
// 将字典数组转换为 JSON 数据
|
|
77
|
+
NSError *error = nil;
|
|
78
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:deviceArray options:NSJSONWritingPrettyPrinted error:&error];
|
|
79
|
+
if (error) {
|
|
80
|
+
NSLog(@"Error converting to JSON: %@", error.localizedDescription);
|
|
81
|
+
reject(@"JSON_SERIALIZATION_ERROR", @"Failed to serialize Bluetooth devices", nil);
|
|
82
|
+
} else {
|
|
83
|
+
// 将 JSON 数据转换为 JSON 字符串
|
|
84
|
+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
85
|
+
NSLog(@"JSON String: %@", jsonString);
|
|
86
|
+
resolve(jsonString);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
@catch (NSException *exception) {
|
|
90
|
+
reject(@"ERROR", exception.reason, nil);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// 连接蓝牙设备
|
|
95
|
+
/// - Parameter resolve: 连接成功回调
|
|
96
|
+
/// - Parameter reject: 连接失败回调 0:连接失败 3:用户拒绝授权 4:系统蓝牙开关关闭
|
|
97
|
+
RCT_EXPORT_METHOD(connectToDeviceFromCloudDeviceNO:(NSString *)deviceNO
|
|
98
|
+
timeout:(nonnull NSNumber *)second
|
|
99
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
100
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
101
|
+
[[BDTBluetoothManager shared] connectPeripheralDeviceNO:deviceNO timeout:[second intValue] callback:^(NSInteger state) {
|
|
102
|
+
if (state == 1) {
|
|
103
|
+
resolve(@"1");
|
|
104
|
+
} else {
|
|
105
|
+
NSError *error = [NSError errorWithDomain:@"" code:state userInfo:nil];
|
|
106
|
+
NSString *codeStr = [NSString stringWithFormat:@"%ld",(long)state];
|
|
107
|
+
reject(codeStr,@"connect fail",error);
|
|
108
|
+
}
|
|
109
|
+
}];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// 断开蓝牙设备连接
|
|
113
|
+
/// - Parameter resolve: 连接成功回调
|
|
114
|
+
/// - Parameter reject: 连接失败回调
|
|
115
|
+
RCT_EXPORT_METHOD(disConnectWithDeviceUUID:(NSString *)identifier resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
116
|
+
[[BDTBluetoothManager shared] disconnect:identifier callback:^(NSInteger result) {
|
|
117
|
+
if (result == 1) {
|
|
118
|
+
NSLog(@"断开连接成功");
|
|
119
|
+
resolve(@"1");
|
|
120
|
+
} else {
|
|
121
|
+
NSLog(@"断开连接失败");
|
|
122
|
+
NSError *error = [NSError errorWithDomain:@"" code:0 userInfo:nil];
|
|
123
|
+
reject(@"0",@"connect fail",error);
|
|
124
|
+
}
|
|
125
|
+
}];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// 向蓝牙设备写入信息
|
|
129
|
+
/// - Parameter resolve: 写入成功回调
|
|
130
|
+
/// - Parameter reject: 写入失败回调 0: 写入失败 3:用户拒绝授权 4:系统蓝牙开关关闭
|
|
131
|
+
RCT_EXPORT_METHOD(writeData:(NSString *)base64String
|
|
132
|
+
deviceNO:(NSString *)deviceNO
|
|
133
|
+
command:(nonnull NSNumber *)command
|
|
134
|
+
encrypted:(nonnull NSNumber *)encrypted
|
|
135
|
+
writeCallBack:(RCTResponseSenderBlock)callback) {
|
|
136
|
+
NSData *decodedData = nil;
|
|
137
|
+
if (base64String.length > 0) {
|
|
138
|
+
decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
|
139
|
+
// 确保解码成功后,你可以继续处理数据
|
|
140
|
+
if (decodedData) {
|
|
141
|
+
// 处理解码后的NSData数据
|
|
142
|
+
NSLog(@"解码成功%@", decodedData);
|
|
143
|
+
} else {
|
|
144
|
+
NSLog(@"解码base64String失败");
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
decodedData = [NSData data];
|
|
148
|
+
}
|
|
149
|
+
uint8_t commandValue = [command shortValue];
|
|
150
|
+
BOOL isEncrypted = [encrypted boolValue];
|
|
151
|
+
[[BDTBluetoothManager shared] sendBusinessData:decodedData
|
|
152
|
+
deviceId:deviceNO
|
|
153
|
+
command:commandValue
|
|
154
|
+
opcode:0
|
|
155
|
+
attrType:0
|
|
156
|
+
encrypted:isEncrypted
|
|
157
|
+
callback:^(NSInteger result) {
|
|
158
|
+
if (result == 1) {
|
|
159
|
+
callback(@[@1]);
|
|
160
|
+
} else {
|
|
161
|
+
callback(@[@(result)]);
|
|
162
|
+
}
|
|
163
|
+
} resultCallBack:^(NSData * _Nonnull data) {
|
|
164
|
+
NSString *base64String = [data base64EncodedStringWithOptions:0];
|
|
165
|
+
NSLog(@"内容 (Base64): %@", base64String);
|
|
166
|
+
if ([base64String length] > 0) {
|
|
167
|
+
[self listenBluetoolthType:0 info:base64String];
|
|
168
|
+
} else {
|
|
169
|
+
NSLog(@"无效数据");
|
|
170
|
+
}
|
|
171
|
+
}];
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
RCT_EXPORT_METHOD(writeInfo:(nullable NSString *)base64Payload
|
|
176
|
+
deviceNO:(NSString *)deviceNO
|
|
177
|
+
command:(nonnull NSNumber *)command
|
|
178
|
+
opcode:(nonnull NSNumber *)opCode
|
|
179
|
+
attrType:(nonnull NSNumber *)attrType
|
|
180
|
+
encrypted:(nonnull NSNumber *)encrypted
|
|
181
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
182
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
183
|
+
NSData *decodedData = nil;
|
|
184
|
+
if (base64Payload.length > 0) {
|
|
185
|
+
decodedData = [[NSData alloc] initWithBase64EncodedString:base64Payload options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
|
186
|
+
// 确保解码成功后,你可以继续处理数据
|
|
187
|
+
if (decodedData) {
|
|
188
|
+
// 处理解码后的NSData数据
|
|
189
|
+
NSLog(@"解码成功%@", decodedData);
|
|
190
|
+
} else {
|
|
191
|
+
NSLog(@"解码base64String失败");
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
decodedData = [NSData data];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
uint8_t commandValue = [command shortValue];
|
|
198
|
+
uint8_t opCodeValue = [opCode shortValue];
|
|
199
|
+
uint16_t attrTypeValue = [attrType shortValue];
|
|
200
|
+
BOOL isEncrypted = [encrypted boolValue];
|
|
201
|
+
[[BDTBluetoothManager shared] sendBusinessData:decodedData
|
|
202
|
+
deviceId:deviceNO
|
|
203
|
+
command:commandValue
|
|
204
|
+
opcode:opCodeValue
|
|
205
|
+
attrType:attrTypeValue
|
|
206
|
+
encrypted:isEncrypted
|
|
207
|
+
callback:^(NSInteger result) {
|
|
208
|
+
if (result != 1) {
|
|
209
|
+
reject([NSString stringWithFormat:@"%ld",(long)result], @"写入失败", nil);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
} resultCallBack:^(NSData * _Nonnull data) {
|
|
213
|
+
NSString *base64String = [data base64EncodedStringWithOptions:0];
|
|
214
|
+
NSDictionary *resDict = @{
|
|
215
|
+
@"type": @1,
|
|
216
|
+
@"data": base64String ?: @""
|
|
217
|
+
};
|
|
218
|
+
resolve(resDict); // ✅ Promise resolve 统一返回
|
|
219
|
+
}];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
- (NSString *)convertToHex:(NSData *)data {
|
|
224
|
+
NSMutableString *hexString = [NSMutableString stringWithCapacity:[data length] * 2];
|
|
225
|
+
const unsigned char *dataBuffer = [data bytes];
|
|
226
|
+
for (NSInteger i = 0; i < [data length]; i++) {
|
|
227
|
+
[hexString appendFormat:@"%02X ", dataBuffer[i]];
|
|
228
|
+
}
|
|
229
|
+
return hexString;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/// 获取随机数
|
|
233
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(generateRandom16BytesString) {
|
|
234
|
+
NSData *data = [self generateRandom16Bytes];
|
|
235
|
+
NSLog(@"随机数%@",data);
|
|
236
|
+
NSString *base64String = [data base64EncodedStringWithOptions:0];
|
|
237
|
+
return base64String;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
- (NSData *)generateRandom16Bytes {
|
|
241
|
+
NSMutableData *randomData = [NSMutableData dataWithLength:16]; // 创建一个16字节的空数据对象
|
|
242
|
+
int result = SecRandomCopyBytes(kSecRandomDefault, 16, randomData.mutableBytes); // 生成随机字节
|
|
243
|
+
|
|
244
|
+
if (result != errSecSuccess) {
|
|
245
|
+
NSLog(@"Error generating random bytes: %d", result);
|
|
246
|
+
return nil; // 发生错误时返回 nil
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return randomData; // 返回生成的16字节随机数据
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
/// 获取蓝牙状态
|
|
254
|
+
/// - Parameter callback: 0:未决定蓝牙权限 1:蓝牙权限受限 2:拒绝蓝牙权限 3:已授权蓝牙权限
|
|
255
|
+
RCT_EXPORT_METHOD(getBluetoothState:(RCTResponseSenderBlock)callback) {
|
|
256
|
+
NSInteger state = [[BDTBluetoothManager shared] getBluetoothState];
|
|
257
|
+
NSNumber *stateNum = [NSNumber numberWithInteger:state];
|
|
258
|
+
callback(@[stateNum]);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
///// 从蓝牙设备读取信息
|
|
264
|
+
///// - Parameter resolve: 读取成功回调
|
|
265
|
+
///// - Parameter reject: 读取失败回调
|
|
266
|
+
//RCT_EXPORT_METHOD(listenDeviceID:(NSString *)identifier characteristic:(NSString *)characteristic) {
|
|
267
|
+
// [[YDBluetoolthManager shared] startListeningForCharacteristicUpdates:identifier characteristicUUID:characteristic callback:^(NSData * _Nonnull data) {
|
|
268
|
+
// //note: 根据需求需要将data进行转化
|
|
269
|
+
//
|
|
270
|
+
//
|
|
271
|
+
// }];
|
|
272
|
+
//}
|
|
273
|
+
|
|
274
|
+
/// 监听蓝牙通知
|
|
275
|
+
/// - Parameter type: 0-写入resp、1-蓝牙状态、2-设备连接状态
|
|
276
|
+
/// - Parameter info: 返回值
|
|
277
|
+
- (void)listenBluetoolthType:(NSInteger)type info:(NSString *)base64String {
|
|
278
|
+
[self sendEventWithName:@"listenBluetoolth" body:@{@"type":[NSString stringWithFormat:@"%ld",(long)type],@"message":base64String}];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
RCT_EXPORT_METHOD(fetchCurrentWifiName:(RCTResponseSenderBlock)callback) {
|
|
283
|
+
NSString *name = [[BDTBluetoothManager shared] fetchCurrentWiFiSSID];
|
|
284
|
+
NSLog(@"wifi名称:%@",name);
|
|
285
|
+
callback(@[name]);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
- (NSArray<CBUUID *> *)convertToCBUUIDArrayFromUUIDString:(NSString *)uuidString {
|
|
290
|
+
// 1. 按逗号分割字符串
|
|
291
|
+
NSArray<NSString *> *uuidStrings = [uuidString componentsSeparatedByString:@","];
|
|
292
|
+
|
|
293
|
+
// 2. 创建可变数组存储 CBUUID
|
|
294
|
+
NSMutableArray<CBUUID *> *cbuuids = [[NSMutableArray alloc] init];
|
|
295
|
+
|
|
296
|
+
// 3. 遍历处理每个子字符串
|
|
297
|
+
for (NSString *uuid in uuidStrings) {
|
|
298
|
+
// 去除首尾空格
|
|
299
|
+
NSString *trimmedUUID = [uuid stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
300
|
+
|
|
301
|
+
// 跳过空字符串
|
|
302
|
+
if (trimmedUUID.length == 0) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 4. 创建 CBUUID 对象
|
|
307
|
+
CBUUID *cbuuid = [CBUUID UUIDWithString:trimmedUUID];
|
|
308
|
+
if (cbuuid) {
|
|
309
|
+
[cbuuids addObject:cbuuid];
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// 5. 返回不可变数组
|
|
314
|
+
return [cbuuids copy];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//打开蓝牙卡片
|
|
318
|
+
RCT_EXPORT_METHOD(startMiniAppForBluetoolthDevice:(NSString *)bundleFilePath
|
|
319
|
+
parameters:(NSDictionary *)params
|
|
320
|
+
startWithResolver:(RCTPromiseResolveBlock)resolve
|
|
321
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
322
|
+
{
|
|
323
|
+
|
|
324
|
+
// NSLog(@"startMiniAppForBluetoolthDevice %@",bundleFilePath);
|
|
325
|
+
// dispatch_async(dispatch_get_main_queue(),^{
|
|
326
|
+
// //关闭IQKeyboardManager
|
|
327
|
+
// [[ExposeToRNMethodManager sharedInstance] setIQKeyboardManagerEnabled:FALSE];
|
|
328
|
+
//
|
|
329
|
+
// NSURL *bundleURL = [NSURL URLWithString:bundleFilePath];
|
|
330
|
+
// AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
331
|
+
// appDelegate.bundleURL = bundleURL;
|
|
332
|
+
// appDelegate.rnParams = params;
|
|
333
|
+
//
|
|
334
|
+
// NSMutableDictionary *muParams = [[NSMutableDictionary alloc]initWithDictionary:appDelegate.rnParams];
|
|
335
|
+
// [muParams setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"appVersion"];
|
|
336
|
+
//
|
|
337
|
+
// RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:appDelegate launchOptions:nil];
|
|
338
|
+
// UIView *view = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"miniapp" initialProperties:muParams];
|
|
339
|
+
// UIViewController *bridgeVC = [UIViewController new];
|
|
340
|
+
// bridgeVC.view = view;
|
|
341
|
+
// bridgeVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
342
|
+
// UIViewController *currentVC = [LCTool topViewController];
|
|
343
|
+
// if ([currentVC isKindOfClass:[UINavigationController class]]) {
|
|
344
|
+
// [(UINavigationController *)currentVC pushViewController:bridgeVC animated:false];
|
|
345
|
+
// [(UINavigationController *)currentVC setNavigationBarHidden:YES animated:NO];
|
|
346
|
+
// }else{
|
|
347
|
+
// [currentVC.navigationController pushViewController:bridgeVC animated:false];
|
|
348
|
+
// [currentVC.navigationController setNavigationBarHidden:YES animated:NO];
|
|
349
|
+
// }
|
|
350
|
+
// [NSTimer scheduledTimerWithTimeInterval:1 repeats:NO block:^(NSTimer * _Nonnull timer) {
|
|
351
|
+
// [view setBackgroundColor:[UIColor whiteColor]];
|
|
352
|
+
// }];
|
|
353
|
+
//
|
|
354
|
+
// });
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
//跳转到指南针界面
|
|
358
|
+
RCT_EXPORT_METHOD(jumpCompassView) {
|
|
359
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
360
|
+
[[BDTBluetoothManager shared] jumpCompassView];
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
//插入北斗蓝牙短信
|
|
366
|
+
RCT_EXPORT_METHOD(insertMsg:(NSString *)phone
|
|
367
|
+
content:(NSString *)info
|
|
368
|
+
timestamp:(nonnull NSNumber *)time
|
|
369
|
+
isSend:(BOOL)send) {
|
|
370
|
+
NSTimeInterval timeInterval = [time doubleValue];
|
|
371
|
+
[[BDTChatDBManager shared] insertMessage:info toPhoneNumber:phone isSent:send timestamp:timeInterval];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
//获取会话列表
|
|
375
|
+
RCT_EXPORT_METHOD(getAllConversations:(RCTPromiseResolveBlock)resolve
|
|
376
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
377
|
+
NSArray *array = [[BDTChatDBManager shared] getAllConversations];
|
|
378
|
+
NSError *error;
|
|
379
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
|
|
380
|
+
if (jsonData) {
|
|
381
|
+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
382
|
+
resolve(jsonString);
|
|
383
|
+
} else {
|
|
384
|
+
reject(@"json_error", @"序列化失败", error);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
//获取会话详情
|
|
389
|
+
RCT_EXPORT_METHOD(getMessagesForPhone:(NSString *)phone
|
|
390
|
+
page:(nonnull NSNumber *)page
|
|
391
|
+
pageSize:(nonnull NSNumber *)size
|
|
392
|
+
response:(RCTResponseSenderBlock)callback) {
|
|
393
|
+
NSArray *array = [[BDTChatDBManager shared] getMessagesForPhone:phone page:(NSUInteger)page pageSize:(NSUInteger)size];
|
|
394
|
+
NSError *error;
|
|
395
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
|
|
396
|
+
NSString *jsonString = @"";
|
|
397
|
+
if (jsonData) {
|
|
398
|
+
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
399
|
+
NSLog(@"%@", jsonString);
|
|
400
|
+
} else {
|
|
401
|
+
NSLog(@"JSON serialization error: %@", error);
|
|
402
|
+
}
|
|
403
|
+
callback(@[jsonString]);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
RCT_EXPORT_METHOD(setBLEKey:(NSString *)bleKey
|
|
408
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
409
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
410
|
+
[BDTBluetoothManager shared].bleKeyHex = bleKey;
|
|
411
|
+
resolve(@(1)); // 可以返回任意值,表示成功
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
判断蓝牙权限:0-未明确 1-受限的/未授权 2-拒绝 3-已授权
|
|
416
|
+
*/
|
|
417
|
+
RCT_EXPORT_METHOD(initializeBluetooth:(RCTResponseSenderBlock)callBack){
|
|
418
|
+
[[BDTBluetoothManager shared] getBluetoothAuthorizationStatus:^(NSString *status) {
|
|
419
|
+
callBack(@[status]);
|
|
420
|
+
}];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
@end
|
|
Binary file
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BDTBluetoothManager.h
|
|
3
|
+
// BeidouBluetooth
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/8/12.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <CoreBluetooth/CoreBluetooth.h>
|
|
10
|
+
#import <BeidouBluetooth/BDTDataPacketBuilder.h>
|
|
11
|
+
|
|
12
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
13
|
+
|
|
14
|
+
@protocol BDTBluetoothMonitor <NSObject>
|
|
15
|
+
|
|
16
|
+
- (void)listenBluetoolthType:(NSInteger)type info:(NSString *)base64String;
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
@interface BDTBluetoothDevice : NSObject
|
|
21
|
+
@property (nonatomic, strong) CBPeripheral *peripheral;
|
|
22
|
+
@property (nonatomic, copy, nullable) NSString *name;
|
|
23
|
+
@property (nonatomic, strong) NSUUID *identifier;
|
|
24
|
+
@property (nonatomic, assign) NSInteger rssi;
|
|
25
|
+
@property (nonatomic, assign) NSNumber *venderID; //厂商标识
|
|
26
|
+
@property (nonatomic, copy) NSString *productID; //产品标识
|
|
27
|
+
@property (nonatomic, copy) NSString *deviceNO; //设备标识
|
|
28
|
+
@property (nonatomic, assign) NSInteger maxPacketSize;
|
|
29
|
+
@end
|
|
30
|
+
|
|
31
|
+
@interface BDTBluetoothManager : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate>
|
|
32
|
+
|
|
33
|
+
@property (nonatomic,weak) id<BDTBluetoothMonitor>delegate;
|
|
34
|
+
|
|
35
|
+
@property(nonatomic,assign)NSInteger state;
|
|
36
|
+
|
|
37
|
+
@property(nonatomic,copy)NSString *bleKeyHex;
|
|
38
|
+
|
|
39
|
+
+ (instancetype)shared;
|
|
40
|
+
|
|
41
|
+
// 公共方法
|
|
42
|
+
- (void)startScanningForServices:(nullable NSArray<CBUUID *> *)serviceUUIDs callBack:(void (^)(NSInteger))callback;
|
|
43
|
+
|
|
44
|
+
- (void)stopScanning;
|
|
45
|
+
|
|
46
|
+
- (NSArray<BDTBluetoothDevice *> *)getDiscoveredDevices;
|
|
47
|
+
|
|
48
|
+
- (void)connectPeripheralDeviceNO:(NSString *)deviceNO
|
|
49
|
+
timeout:(NSInteger)second
|
|
50
|
+
callback:(void (^)(NSInteger))callback;
|
|
51
|
+
|
|
52
|
+
- (void)disconnect:(NSString *)deviceNO
|
|
53
|
+
callback:(void (^)(NSInteger result))callback;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
- (void)sendBusinessData:(nullable NSData *)data
|
|
57
|
+
deviceId:(NSString *)deviceNO
|
|
58
|
+
command:(BDTCommand)command
|
|
59
|
+
opcode:(BDTCommand)opCode
|
|
60
|
+
attrType:(uint16_t)attrType
|
|
61
|
+
encrypted:(BOOL)isEncrypted
|
|
62
|
+
callback:(void (^)(NSInteger result))callback
|
|
63
|
+
resultCallBack:(void (^)(NSData *data))handle;
|
|
64
|
+
|
|
65
|
+
- (NSInteger)getBluetoothState;
|
|
66
|
+
|
|
67
|
+
- (void)jumpCompassView;
|
|
68
|
+
|
|
69
|
+
- (nullable NSString *)fetchCurrentWiFiSSID;
|
|
70
|
+
|
|
71
|
+
- (void)getBluetoothAuthorizationStatus:(nullable void(^)(NSString *status))completed;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@end
|
|
75
|
+
|
|
76
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BDTChatDBManager.h
|
|
3
|
+
// BeidouBluetooth
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/10/10.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
11
|
+
|
|
12
|
+
@interface BDTChatDBManager : NSObject
|
|
13
|
+
|
|
14
|
+
/// 单例入口
|
|
15
|
+
+ (instancetype)shared;
|
|
16
|
+
|
|
17
|
+
/// 插入新消息(自动维护对话列表)
|
|
18
|
+
/// @param content 消息内容
|
|
19
|
+
/// @param phoneNumber 对方电话号码
|
|
20
|
+
/// @param isSend 是否是自己发送
|
|
21
|
+
/// @param timestamp 时间戳
|
|
22
|
+
- (void)insertMessage:(NSString *)content
|
|
23
|
+
toPhoneNumber:(NSString *)phoneNumber
|
|
24
|
+
isSent:(BOOL)isSend
|
|
25
|
+
timestamp:(NSTimeInterval)timestamp;
|
|
26
|
+
|
|
27
|
+
/// 获取所有对话列表(按最后时间倒序)
|
|
28
|
+
/// @return 格式:@[@{@"phone": @"13800138000", @"lastMsg": @"你好", @"timestamp": @1648888888}]
|
|
29
|
+
- (NSArray<NSDictionary *> *)getAllConversations;
|
|
30
|
+
|
|
31
|
+
/// 获取某个对话的聊天记录(分页加载)
|
|
32
|
+
/// @param phoneNumber 对方号码
|
|
33
|
+
/// @param page 页码(从0开始)
|
|
34
|
+
/// @param pageSize 每页数量
|
|
35
|
+
- (NSArray<NSDictionary *> *)getMessagesForPhone:(NSString *)phoneNumber
|
|
36
|
+
page:(NSUInteger)page
|
|
37
|
+
pageSize:(NSUInteger)pageSize;
|
|
38
|
+
|
|
39
|
+
@end
|
|
40
|
+
|
|
41
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BDTDataPacketBuilder.h
|
|
3
|
+
// BeidouBluetooth
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/8/13.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
11
|
+
|
|
12
|
+
// 定义指令枚举
|
|
13
|
+
typedef NS_ENUM(uint8_t, BDTCommand) {
|
|
14
|
+
CommandInvalid = 0x00, // 无效/占位
|
|
15
|
+
CommandType1 = 0x01, //蓝牙设备主动上报的设备状态
|
|
16
|
+
CommandType2 = 0x02, //手机 App 发出请求指令,需要设备回复,与0x03 对应
|
|
17
|
+
CommandType3 = 0x03, //蓝牙设备回复请求指令,与 0x02 对应
|
|
18
|
+
CommandType4 = 0x04, //蓝牙设备发出请求指令,需要手机 App,与0x05 对应
|
|
19
|
+
CommandType5 = 0x05, //手机 App 回复请求指令,与 0x04 对应
|
|
20
|
+
CommandType6 = 0x10, //连接建立指令集 - 下发随机数到设备
|
|
21
|
+
CommandType7 = 0x12, //连接建立指令集 - 告诉设备平台已验证通过
|
|
22
|
+
PayloadCommand0 = 0xD0,
|
|
23
|
+
PayloadCommand1 = 0xD1,
|
|
24
|
+
PayloadCommandType2 = 0xD2,
|
|
25
|
+
PayloadCommandType3 = 0xD3,
|
|
26
|
+
PayloadCommandType4 = 0xD4,
|
|
27
|
+
PayloadCommandType5 = 0xD5,
|
|
28
|
+
PayloadCommandType6 = 0xD6,
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
@interface BDTDataPacketBuilder : NSObject
|
|
33
|
+
|
|
34
|
+
// 方法:拼接 4 个字节(32bit)数据
|
|
35
|
+
+ (NSData *)assemblePacketWithMessageID:(uint8_t)messageID
|
|
36
|
+
encryptFlag:(BOOL)encryptFlag
|
|
37
|
+
version:(uint8_t)version
|
|
38
|
+
command:(BDTCommand)command
|
|
39
|
+
frameSequence:(uint8_t)frameSequence
|
|
40
|
+
totalFragments:(uint8_t)totalFragments
|
|
41
|
+
payloadLength:(uint8_t)payloadLength;
|
|
42
|
+
|
|
43
|
+
+ (NSData *)assemblePayloadWithEnumValue:(BDTCommand)enumValue
|
|
44
|
+
numberValue:(uint8_t)numberValue
|
|
45
|
+
attrType:(uint16_t)attrType
|
|
46
|
+
attrValue:(NSData *)contentInfo;
|
|
47
|
+
|
|
48
|
+
+ (NSData *)completePacket:(NSData *)headerData payload:(NSData *)payloadData;
|
|
49
|
+
|
|
50
|
+
+ (NSData *)generateRandom16Bytes;
|
|
51
|
+
|
|
52
|
+
+ (NSData *)aes128CBCEncryptData:(NSData *)plainData
|
|
53
|
+
withHexKey:(NSString *)hexKey;
|
|
54
|
+
|
|
55
|
+
+ (NSData *)aes128CBCDecryptData:(NSData *)cipherData
|
|
56
|
+
withHexKey:(NSString *)hexKey;
|
|
57
|
+
|
|
58
|
+
+ (NSData *)dataFromHexString:(NSString *)hexString;
|
|
59
|
+
|
|
60
|
+
@end
|
|
61
|
+
|
|
62
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BeidouBluetooth.h
|
|
3
|
+
// BeidouBluetooth
|
|
4
|
+
//
|
|
5
|
+
// Created by 董建伟 on 2025/8/12.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
//! Project version number for BeidouBluetooth.
|
|
11
|
+
FOUNDATION_EXPORT double BeidouBluetoothVersionNumber;
|
|
12
|
+
|
|
13
|
+
//! Project version string for BeidouBluetooth.
|
|
14
|
+
FOUNDATION_EXPORT const unsigned char BeidouBluetoothVersionString[];
|
|
15
|
+
|
|
16
|
+
// In this header, you should import all the public headers of your framework using statements like #import <BeidouBluetooth/PublicHeader.h>
|
|
17
|
+
|
|
18
|
+
#import <BeidouBluetooth/BDTBluetoothManager.h>
|
|
19
|
+
#import <BeidouBluetooth/BDTDataPacketBuilder.h>
|
|
20
|
+
#import <BeidouBluetooth/BDTChatDBManager.h>
|
|
21
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|