Skip to content

Commit 10067a2

Browse files
authored
Merge pull request #512 from Polidea/release/2.3.0
Release 2.3.0
2 parents 199c4d3 + d155791 commit 10067a2

File tree

7 files changed

+39
-3
lines changed

7 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.3.0
2+
3+
* add `BleManager.createUnsafePeripheral()` to allow for connecting to known peripheral without launching scan first
4+
**NOTE:** this change will not work with BLEmulator below 1.2.0
5+
16
## 2.2.9
27

38
* Fixed issue with incorrectly typed Stream

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ It filters the scan results to those that advertise a service with specified UUI
122122

123123
**NOTE:** `isConnectable` and `overflowServiceUuids` fields of `ScanResult` are iOS-only and remain `null` on Android.
124124

125+
126+
### Connecting to saved peripheral
127+
128+
You can try to connect to a peripheral with known ID, be it previously scanned UUID on iOS or a MAC address on Android, and avoid the whole scanning operation in your application. To do so, you need to create an instance of `Peripheral` using:
129+
```dart
130+
Peripheral myPeripheral = bleManager.createUnsafePeripheral("< known id >");
131+
```
132+
Once you have the instance of the peripheral, you may proceed with the connection. But keep in mind
133+
that [Android may still not find the peripheral without scanning it first](https://stackoverflow.com/questions/43476369/android-save-ble-device-to-reconnect-after-app-close/43482099#43482099).
134+
125135
### Connecting to peripheral
126136

127137
First you must obtain a _ScanResult_ from _BleManager.startPeripheralScan()_.

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.polidea.flutter_ble_lib'
2-
version '2.2.9'
2+
version '2.3.0'
33

44
buildscript {
55
repositories {

ios/flutter_ble_lib.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'flutter_ble_lib'
6-
s.version = '2.2.9'
6+
s.version = '2.3.0'
77
s.summary = 'A new flutter plugin project.'
88
s.description = <<-DESC
99
A new flutter plugin project.

lib/ble_manager.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ abstract class BleManager {
137137
///
138138
/// If [serviceUUIDs] is empty, this will return an empty list.
139139
Future<List<Peripheral>> connectedPeripherals(List<String> serviceUUIDs);
140+
141+
/// Creates a peripheral which may not exist or be available. Since the
142+
/// [peripheralId] might be a UUID or a MAC address,
143+
/// depending on the platform, its format is not validated.
144+
///
145+
/// On iOS [peripheralId] is unique for a particular device
146+
/// and will not be recognized on any different device.
147+
/// On Android [peripheralId] scanned on one device may or may not be
148+
/// recognized on a different Android device depending on peripheral’s
149+
/// implementation and changes in future OS releases.
150+
Peripheral createUnsafePeripheral(String peripheralId, {String name});
140151
}
141152

142153
/// State of the Bluetooth Adapter.

lib/src/internal_ble_manager.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ class InternalBleManager
6262
@override
6363
Future<void> stopPeripheralScan() => _bleLib.stopDeviceScan();
6464

65+
@override
66+
Peripheral createUnsafePeripheral(String peripheralId, {String name}) {
67+
const nameField = 'name';
68+
const identifierField = 'id';
69+
return Peripheral.fromJson({
70+
nameField: name,
71+
identifierField: peripheralId,
72+
}, this);
73+
}
74+
6575
@override
6676
Future<void> connectToPeripheral(
6777
String identifier, {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_ble_lib
22
description: FlutterBle Library is a flutter library that supports BLE operations. It uses MultiPlatformBleAdapter as a native backend..
3-
version: 2.2.9
3+
version: 2.3.0
44
homepage: https://github.com/Polidea/FlutterBleLib
55

66
environment:

0 commit comments

Comments
 (0)