Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosinigaglia committed Sep 20, 2018
2 parents a2744a4 + ca4fffa commit 3474217
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
11 changes: 7 additions & 4 deletions android/src/main/java/it/innove/Peripheral.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ public WritableMap asWritableMap() {
map.putString("id", device.getAddress()); // mac address
map.putInt("rssi", advertisingRSSI);

if (advertisingData != null)
advertising.putString("localName", advertisingData.getDeviceName().replace("\0", ""));
else
advertising.putString("localName", device.getName());
String name = device.getName();
if (name != null)
advertising.putString("localName", name);

advertising.putMap("manufacturerData", byteArrayToWritableMap(advertisingDataBytes));
advertising.putBoolean("isConnectable", true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && advertisingData != null) {
String deviceName = advertisingData.getDeviceName();
if (deviceName != null)
advertising.putString("localName", deviceName.replace("\0", ""));

WritableArray serviceUuids = Arguments.createArray();
if (advertisingData.getServiceUuids() != null && advertisingData.getServiceUuids().size() != 0) {
for (ParcelUuid uuid : advertisingData.getServiceUuids()) {
Expand Down
16 changes: 10 additions & 6 deletions ios/BleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,20 @@ - (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForChara
NSString *key = [self keyForPeripheral: peripheral andCharacteristic:characteristic];

if (characteristic.isNotifying) {
NSLog(@"Notification began on %@", characteristic.UUID);
RCTResponseSenderBlock notificationCallback = [notificationCallbacks objectForKey:key];
notificationCallback(@[]);
[notificationCallbacks removeObjectForKey:key];
if (notificationCallback != nil) {
NSLog(@"Notification began on %@", characteristic.UUID);
notificationCallback(@[]);
[notificationCallbacks removeObjectForKey:key];
}
} else {
// Notification has stopped
NSLog(@"Notification ended on %@", characteristic.UUID);
RCTResponseSenderBlock stopNotificationCallback = [stopNotificationCallbacks objectForKey:key];
stopNotificationCallback(@[]);
[stopNotificationCallbacks removeObjectForKey:key];
if (stopNotificationCallback != nil) {
NSLog(@"Notification ended on %@", characteristic.UUID);
stopNotificationCallback(@[]);
[stopNotificationCallbacks removeObjectForKey:key];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/CBPeripheral+Extensions.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ - (void) serviceAndCharacteristicInfo: (NSMutableDictionary *) info {
[characteristicDictionary setObject:[[service UUID] UUIDString] forKey:@"service"];
[characteristicDictionary setObject:[[characteristic UUID] UUIDString] forKey:@"characteristic"];

if ([characteristic value]) {
if ([characteristic value] && [[characteristic value] length] > 0) {
[characteristicDictionary setObject:dataToArrayBuffer([characteristic value]) forKey:@"value"];
}
if ([characteristic properties]) {
Expand Down

0 comments on commit 3474217

Please sign in to comment.