react-native-bluetooth-escpos-printer-fork 0.0.19 → 0.0.21
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/ios/RNBluetoothManager.m +38 -61
- package/package.json +1 -1
package/ios/RNBluetoothManager.m
CHANGED
|
@@ -236,30 +236,13 @@ RCT_EXPORT_METHOD(scanDevices:(RCTPromiseResolveBlock)resolve
|
|
|
236
236
|
NSString *name = connected.name ? connected.name : @"";
|
|
237
237
|
NSString *address = connected.identifier.UUIDString;
|
|
238
238
|
|
|
239
|
-
// Create device info with device class for connected device
|
|
240
239
|
NSMutableDictionary *deviceInfo = [[NSMutableDictionary alloc] init];
|
|
241
240
|
[deviceInfo setObject:address forKey:@"address"];
|
|
242
241
|
[deviceInfo setObject:name forKey:@"name"];
|
|
243
|
-
[deviceInfo setObject:@(0) forKey:@"rssi"];
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
NSString *upperName = name.uppercaseString;
|
|
248
|
-
if ([upperName containsString:@"PRINT"] ||
|
|
249
|
-
[upperName containsString:@"POS"] ||
|
|
250
|
-
[upperName containsString:@"ESCPOS"] ||
|
|
251
|
-
[upperName containsString:@"THERMAL"] ||
|
|
252
|
-
[upperName containsString:@"RECEIPT"]) {
|
|
253
|
-
isPrinter = YES;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (isPrinter) {
|
|
257
|
-
[deviceInfo setObject:@(1536) forKey:@"majorDeviceClass"]; // Imaging
|
|
258
|
-
[deviceInfo setObject:@(1664) forKey:@"deviceClass"]; // Printer
|
|
259
|
-
} else {
|
|
260
|
-
[deviceInfo setObject:@(7936) forKey:@"majorDeviceClass"]; // Unknown
|
|
261
|
-
[deviceInfo setObject:@(7936) forKey:@"deviceClass"]; // Unknown
|
|
262
|
-
}
|
|
242
|
+
[deviceInfo setObject:@(0) forKey:@"rssi"];
|
|
243
|
+
[deviceInfo setObject:@(0) forKey:@"deviceClass"];
|
|
244
|
+
[deviceInfo setObject:@(0) forKey:@"majorDeviceClass"];
|
|
245
|
+
[deviceInfo setObject:@{} forKey:@"advertisementData"];
|
|
263
246
|
|
|
264
247
|
NSDictionary *peripheralStored = @{address:connected};
|
|
265
248
|
if(!self.foundDevices){
|
|
@@ -280,7 +263,7 @@ RCT_EXPORT_METHOD(scanDevices:(RCTPromiseResolveBlock)resolve
|
|
|
280
263
|
[timer invalidate];
|
|
281
264
|
timer = nil;
|
|
282
265
|
}
|
|
283
|
-
timer = [NSTimer scheduledTimerWithTimeInterval:
|
|
266
|
+
timer = [NSTimer scheduledTimerWithTimeInterval:12 target:self selector:@selector(callStop) userInfo:nil repeats:NO];
|
|
284
267
|
|
|
285
268
|
}
|
|
286
269
|
@catch(NSException *exception){
|
|
@@ -540,52 +523,46 @@ RCT_EXPORT_METHOD(unpaire:(NSString *)address
|
|
|
540
523
|
|
|
541
524
|
// Try to infer device class from advertising data
|
|
542
525
|
// iOS BLE doesn't expose Classic Bluetooth device class, but we can make educated guesses
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
//
|
|
526
|
+
// Build advertisementData dictionary for JS layer
|
|
527
|
+
NSMutableDictionary *advData = [[NSMutableDictionary alloc] init];
|
|
528
|
+
|
|
529
|
+
// Service UUIDs
|
|
547
530
|
NSArray *serviceUUIDs = advertisementData[CBAdvertisementDataServiceUUIDsKey];
|
|
548
|
-
BOOL isPrinter = NO;
|
|
549
|
-
|
|
550
531
|
if (serviceUUIDs && serviceUUIDs.count > 0) {
|
|
532
|
+
NSMutableArray *uuidStrings = [[NSMutableArray alloc] init];
|
|
551
533
|
for (CBUUID *uuid in serviceUUIDs) {
|
|
552
|
-
|
|
553
|
-
// Serial Port Profile (SPP) UUID - common for printers
|
|
554
|
-
// Also check for other printer-related service UUIDs
|
|
555
|
-
if ([uuidString isEqualToString:@"00001101-0000-1000-8000-00805F9B34FB"] ||
|
|
556
|
-
[uuidString isEqualToString:@"49535343-FE7D-4AE5-8FA9-9FAFD205E455"] ||
|
|
557
|
-
[uuidString containsString:@"18F0"]) {
|
|
558
|
-
isPrinter = YES;
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
534
|
+
[uuidStrings addObject:uuid.UUIDString];
|
|
561
535
|
}
|
|
536
|
+
[advData setObject:uuidStrings forKey:@"serviceUUIDs"];
|
|
562
537
|
}
|
|
563
|
-
|
|
564
|
-
//
|
|
565
|
-
NSString *
|
|
566
|
-
if (
|
|
567
|
-
[
|
|
568
|
-
[name containsString:@"ESCPOS"] ||
|
|
569
|
-
[name containsString:@"THERMAL"] ||
|
|
570
|
-
[name containsString:@"RECEIPT"]) {
|
|
571
|
-
isPrinter = YES;
|
|
538
|
+
|
|
539
|
+
// Local name (may differ from peripheral.name)
|
|
540
|
+
NSString *localName = advertisementData[CBAdvertisementDataLocalNameKey];
|
|
541
|
+
if (localName) {
|
|
542
|
+
[advData setObject:localName forKey:@"localName"];
|
|
572
543
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
majorDeviceClass = 1536; // 0x0600 in decimal
|
|
579
|
-
deviceClass = 1664; // 0x0680 in decimal
|
|
580
|
-
} else {
|
|
581
|
-
// Unknown/Unclassified device
|
|
582
|
-
// Major Device Class: 0x1F00 (Uncategorized)
|
|
583
|
-
majorDeviceClass = 7936; // 0x1F00 in decimal
|
|
584
|
-
deviceClass = 7936;
|
|
544
|
+
|
|
545
|
+
// Manufacturer data as base64
|
|
546
|
+
NSData *manufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey];
|
|
547
|
+
if (manufacturerData) {
|
|
548
|
+
[advData setObject:[manufacturerData base64EncodedStringWithOptions:0] forKey:@"manufacturerData"];
|
|
585
549
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
550
|
+
|
|
551
|
+
// TX power level
|
|
552
|
+
NSNumber *txPowerLevel = advertisementData[CBAdvertisementDataTxPowerLevelKey];
|
|
553
|
+
if (txPowerLevel) {
|
|
554
|
+
[advData setObject:txPowerLevel forKey:@"txPowerLevel"];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Connectable flag
|
|
558
|
+
NSNumber *isConnectable = advertisementData[CBAdvertisementDataIsConnectable];
|
|
559
|
+
if (isConnectable) {
|
|
560
|
+
[advData setObject:isConnectable forKey:@"isConnectable"];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
[deviceInfo setObject:@(0) forKey:@"deviceClass"];
|
|
564
|
+
[deviceInfo setObject:@(0) forKey:@"majorDeviceClass"];
|
|
565
|
+
[deviceInfo setObject:advData forKey:@"advertisementData"];
|
|
589
566
|
|
|
590
567
|
// Store the peripheral object for connection
|
|
591
568
|
NSDictionary *peripheralStored = @{peripheral.identifier.UUIDString:peripheral};
|