Skip to content

Commit 489c9f4

Browse files
authored
Release 2.2.1
Release 2.2.1
2 parents 7a5e301 + 07e346a commit 489c9f4

21 files changed

+282
-92
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.2.1
2+
3+
* Hide private APIs
4+
* Add setup instructions to README
5+
* Add missing descriptor operations information to README
6+
* Moved permission_handler dependency to its place in example
7+
18
## 2.2.0
29

310
* **NEW** operations on descriptors

README.md

Lines changed: 87 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,83 @@
66

77
# FlutterBleLib
88

9-
A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's
10-
[MultiPlatformBleAdapter](https://github.com/Polidea/MultiPlatformBleAdapter),
9+
A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's
10+
[MultiPlatformBleAdapter](https://github.com/Polidea/MultiPlatformBleAdapter),
1111
which runs on [RxAndroidBle](https://github.com/Polidea/RxAndroidBle)
12-
and [RxBluetoothKit](https://github.com/Polidea/RxBluetoothKit).
12+
and [RxBluetoothKit](https://github.com/Polidea/RxBluetoothKit).
1313

1414
## BLE Simulator
15-
This library supports [BLEmulator](https://github.com/Polidea/blemulator_flutter), the BLE simulator.
15+
16+
This library supports [BLEmulator](https://github.com/Polidea/blemulator_flutter), the BLE simulator.
1617
The simulation allows one to develop without physical smartphone or BLE peripheral and use one's production BLE–related code in automated testing.
1718

19+
## Installation
20+
21+
To use this plugin, add `flutter_ble_lib` as a [dependency in your pubspec.yaml file](https://flutter.dev/docs/development/packages-and-plugins/using-packages).
22+
23+
### Android
24+
25+
Set `minSDKVersion` in `[project]/android/app/build.gradle` file to 18.
26+
27+
```gradle
28+
defaultConfig {
29+
...
30+
minSdkVersion 18
31+
...
32+
}
33+
```
34+
35+
Support for Bluetooth Low Energy has been added in API 18, hence the library requires `minSDKVersion` to be set to 18. If BLE is not core to your application, [you can override it](https://stackoverflow.com/questions/27335889/how-do-i-ignore-minsdkversion-of-library-in-android-studio) and handle support detection in your code.
36+
37+
**Notice:** You don't need to add any permissions related to BLE to the `AndroidManifest.xml`, because they are already declared in the library's native module. However, you still need to request `ACCESS_FINE_LOCATION` permission at runtime to be able to scan for peripheral. See [example's code](https://github.com/Polidea/FlutterBleLib/blob/202c6fe48300be207f80567ca4bee5b6fbc83eb5/example/lib/devices_list/devices_bloc.dart#L80) and [example's pubspec](https://github.com/Polidea/FlutterBleLib/blob/202c6fe48300be207f80567ca4bee5b6fbc83eb5/example/pubspec.yaml#L20).
38+
39+
### iOS
40+
41+
Go to `[project]/ios` directory and run `pod install`.
42+
43+
Add [Privacy - Bluetooth Always Usage Description](https://developer.apple.com/documentation/bundleresources/information_property_list/nsbluetoothalwaysusagedescription) key to `[project]/ios/Runner/Info.plist` file.
44+
45+
```xml
46+
...
47+
<key>NSBluetoothAlwaysUsageDescription</key>
48+
<string>Your own description of the purpose.</string>
49+
...
50+
```
51+
1852
## Usage
19-
To use this plugin, add `flutter_ble_lib` as a [dependency in your pubspec.yaml file](https://pub.dev/packages/flutter_ble_lib/versions/2.0.0-dev.4).
2053

21-
## Overview
2254
The library is organised around a few base entities, which are:
23-
* **BleManager**
24-
* **Peripheral**
25-
* **Service**
26-
* **Characteristic**
2755

28-
You have to create an instance _BleManager_ and initialise underlying native resources.
56+
- **BleManager**
57+
- **Peripheral**
58+
- **Service**
59+
- **Characteristic**
60+
* **Descriptor**
61+
62+
You have to create an instance _BleManager_ and initialise underlying native resources.
2963
Using that instance you then obtain an instance of _Peripheral_,
30-
which can be used to run operations on the corresponding peripheral.
31-
32-
All operations passing the Dart-native bridge are asynchronous,
33-
hence all operations in the plugin return either Future or Stream.
64+
which can be used to run operations on the corresponding peripheral.
65+
66+
All operations passing the Dart-native bridge are asynchronous,
67+
hence all operations in the plugin return either Future or Stream.
3468

3569
For more informations, see [REFERENCE](https://github.com/Polidea/FlutterBleLib/blob/master/REFERENCE.md).
3670

37-
**Notice:** this library will not handle any permissions for you. To be able to scan for peripherals on Android you need `ACCESS_FINE_LOCATION` [according to Android Developer Guide](https://developer.android.com/guide/topics/connectivity/bluetooth-le#permissions).
71+
**Notice:** this library will not handle any permissions for you. To be able to scan for peripherals on Android you need `ACCESS_FINE_LOCATION` [according to Android Developer Guide](https://developer.android.com/guide/topics/connectivity/bluetooth-le#permissions).
3872

3973
### Initialising
74+
4075
```dart
4176
BleManager bleManager = BleManager();
4277
await bleManager.createClient(); //ready to go!
4378
// your peripheral logic
4479
bleManager.destroyClient(); //remember to release native resources when you're done!
4580
```
81+
4682
Following snippets assume the library has been initialised.
4783

4884
### Handling Bluetooth adapter state
85+
4986
```dart
5087
enum BluetoothState {
5188
UNKNOWN,
@@ -65,7 +102,9 @@ bleManager.observeBluetoothState().listen((btState) {
65102
//do your BT logic, open different screen, etc.
66103
});
67104
```
105+
68106
### Scanning for peripherals
107+
69108
```dart
70109
bleManager.startPeripheralScan(
71110
uuids: [
@@ -78,13 +117,15 @@ bleManager.startPeripheralScan(
78117
});
79118
```
80119

81-
The snippet above starts peripheral scan and stops it after receiving first result.
120+
The snippet above starts peripheral scan and stops it after receiving first result.
82121
It filters the scan results to those that advertise a service with specified UUID.
83122

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

86125
### Connecting to peripheral
126+
87127
First you must obtain a _ScanResult_ from _BleManager.startPeripheralScan()_.
128+
88129
```dart
89130
Peripheral peripheral = scanResult.peripheral;
90131
peripheral.observeConnectionState(emitCurrentValue: true, completeOnDisconnect: true)
@@ -97,20 +138,21 @@ await peripheral.disconnectOrCancelConnection();
97138
```
98139

99140
The snippet above starts observing the state of the connection to the peripheral,
100-
connects to it, checks if it's connected and then disconnects from it.
141+
connects to it, checks if it's connected and then disconnects from it.
101142

102143
### Transactions
103144

104145
Methods that do not have counterpart with opposite effect and are asynchronous accept
105-
`String transactionId` as an optional argument, to allow the user to cancel such an operation.
106-
The Future returned to Dart will then finish with a _BleError(BleErrorCode.operationCancelled...)_,
107-
**but this will only discard the result of the operation, the operation itself will be executed either way**.
108-
146+
`String transactionId` as an optional argument, to allow the user to cancel such an operation.
147+
The Future returned to Dart will then finish with a _BleError(BleErrorCode.operationCancelled...)_,
148+
**but this will only discard the result of the operation, the operation itself will be executed either way**.
149+
109150
For example, if I decided that I no longer want to run discovery on the selected peripheral:
151+
110152
```dart
111153
//assuming peripheral is connected
112-
peripheral.discoverAllServicesAndCharacteristics(transactionId: "discovery");
113-
//will return operation cancelled error after calling the below
154+
peripheral.discoverAllServicesAndCharacteristics(transactionId: "discovery");
155+
//will return operation cancelled error after calling the below
114156
bleManager.cancelTransaction("discovery");
115157
```
116158

@@ -136,10 +178,13 @@ List<Characteristic> characteristics2 = await services.firstWhere(
136178
```
137179

138180
Objects representing characteristics have a unique identifer, so they point to one specific characteristic,
139-
even if there are multiple service/characteristic uuid matches.
181+
even if there are multiple service/characteristic uuid matches.
182+
140183
### Manipulating characteristics
184+
141185
Below are 3 methods of writing to a characteristic, which all result in the same effect given
142-
there's only one service with specified UUID and only one characteristic with specified UUID.
186+
there's only one service with specified UUID and only one characteristic with specified UUID.
187+
143188
```dart
144189
peripheral.writeCharacteristic(
145190
"F000AA00-0451-4000-B000-000000000000",
@@ -156,22 +201,32 @@ characteristic.write(Uint8List.fromList([0]), false); //returns void
156201
```
157202

158203
Monitoring or reading a characteristic from _Peripheral_/_Service_ level
159-
return _CharacteristicWithValue_ object, which is _Characteristic_ with additional `Uint8List value` property.
204+
return _CharacteristicWithValue_ object, which is _Characteristic_ with additional `Uint8List value` property.
205+
206+
### Descriptor operations
207+
208+
List of descriptors from a single characteristic can be obtained in a similar fashion to a list of characteristics from a single service, either from Peripheral, Service or Characteristic object.
209+
Descriptors can be read/written from Peripheral, Service or Characteristic by supplying necessary UUIDs, or from Descriptor object.
210+
211+
**Note:** to enable monitoring of characteristic you should use `characteristic.monitor()` or `(peripheral/service).monitorCharacteristic()` instead of changing the value of the underlying descriptor yourself.
160212

161213
## Facilitated by Frontside
162214
[Frontside](https://github.com/thefrontside) provided architectural advice and financial support for this library on behalf of [Resideo](https://github.com/resideo).
163215

164216
## Maintained by
217+
165218
This library is maintained by [Polidea](https://www.polidea.com/?utm_source=Github&utm_medium=Npaid&utm_campaign=Main&utm_term=Code&utm_content=GH_NOP_MPG_COD_FBLE001)
166219

167220
[Contact us](https://www.polidea.com/project/?utm_source=Github&utm_medium=Npaid&utm_campaign=Kontakt&utm_term=Code&utm_content=GH_NOP_KKT_COD_FBLE001)
168221

169222
[Learn more about Polidea's BLE services](https://www.polidea.com/services/ble/?utm_source=Github&utm_medium=Npaid&utm_campaign=Tech_BLE&utm_term=Code&utm_content=GH_NOP_BLE_COD_FBLE001).
170223

171224
#### Maintainers
225+
172226
TBD
173227

174228
## License
229+
175230
Copyright 2019 Polidea Sp. z o.o
176231

177232
Licensed under the Apache License, Version 2.0 (the "License");
@@ -187,7 +242,9 @@ See the License for the specific language governing permissions and
187242
limitations under the License.
188243

189244
## More from Polidea
245+
190246
Check out other Polidea's BLE libraries:
191-
* [react-native-ble-plx](https://github.com/Polidea/react-native-ble-plx)
192-
* [RxAndroidBle](https://github.com/Polidea/RxAndroidBle)
193-
* [RxBluetoothKit](https://github.com/Polidea/RxBluetoothKit)
247+
248+
- [react-native-ble-plx](https://github.com/Polidea/react-native-ble-plx)
249+
- [RxAndroidBle](https://github.com/Polidea/RxAndroidBle)
250+
- [RxBluetoothKit](https://github.com/Polidea/RxBluetoothKit)

0 commit comments

Comments
 (0)