Skip to content

Commit

Permalink
Merge pull request #512 from Polidea/release/2.3.0
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
mikolak authored Aug 25, 2020
2 parents 199c4d3 + d155791 commit 10067a2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.3.0

* add `BleManager.createUnsafePeripheral()` to allow for connecting to known peripheral without launching scan first
**NOTE:** this change will not work with BLEmulator below 1.2.0

## 2.2.9

* Fixed issue with incorrectly typed Stream
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ It filters the scan results to those that advertise a service with specified UUI

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


### Connecting to saved peripheral

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:
```dart
Peripheral myPeripheral = bleManager.createUnsafePeripheral("< known id >");
```
Once you have the instance of the peripheral, you may proceed with the connection. But keep in mind
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).

### Connecting to peripheral

First you must obtain a _ScanResult_ from _BleManager.startPeripheralScan()_.
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.polidea.flutter_ble_lib'
version '2.2.9'
version '2.3.0'

buildscript {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion ios/flutter_ble_lib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'flutter_ble_lib'
s.version = '2.2.9'
s.version = '2.3.0'
s.summary = 'A new flutter plugin project.'
s.description = <<-DESC
A new flutter plugin project.
Expand Down
11 changes: 11 additions & 0 deletions lib/ble_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ abstract class BleManager {
///
/// If [serviceUUIDs] is empty, this will return an empty list.
Future<List<Peripheral>> connectedPeripherals(List<String> serviceUUIDs);

/// Creates a peripheral which may not exist or be available. Since the
/// [peripheralId] might be a UUID or a MAC address,
/// depending on the platform, its format is not validated.
///
/// On iOS [peripheralId] is unique for a particular device
/// and will not be recognized on any different device.
/// On Android [peripheralId] scanned on one device may or may not be
/// recognized on a different Android device depending on peripheral’s
/// implementation and changes in future OS releases.
Peripheral createUnsafePeripheral(String peripheralId, {String name});
}

/// State of the Bluetooth Adapter.
Expand Down
10 changes: 10 additions & 0 deletions lib/src/internal_ble_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ class InternalBleManager
@override
Future<void> stopPeripheralScan() => _bleLib.stopDeviceScan();

@override
Peripheral createUnsafePeripheral(String peripheralId, {String name}) {
const nameField = 'name';
const identifierField = 'id';
return Peripheral.fromJson({
nameField: name,
identifierField: peripheralId,
}, this);
}

@override
Future<void> connectToPeripheral(
String identifier, {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_ble_lib
description: FlutterBle Library is a flutter library that supports BLE operations. It uses MultiPlatformBleAdapter as a native backend..
version: 2.2.9
version: 2.3.0
homepage: https://github.com/Polidea/FlutterBleLib

environment:
Expand Down

0 comments on commit 10067a2

Please sign in to comment.