You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-42Lines changed: 7 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,13 @@
1
1
# SwiftyBluetooth
2
-
Swift 3, fully featured closures based library for CoreBluetooth on iOS 9+ devices.
3
-
4
-
For Swift 2 use v0.1.1
2
+
Fully featured closures based library for CoreBluetooth on iOS 9+ devices.
5
3
6
4
## Background
7
5
CoreBluetooth and its delegate based API can be difficult to use at time. Often times you already know the specifications of the peripheral you're about to use and simply want to read or write to predetermined characteristics.
8
6
9
7
SwiftyBluetooth tries to address these concerns by providing a clear, closure based, API for every `CBCentralManager` and `CBPeripheral` calls. Furthermore, all your calls are guaranteed to timeout in case of untraceable errors. If required, SwiftyBluetooth will also take care of connecting to peripherals and discovering the required attributes when executing read or write operations lowering the amount of work you need to do.
10
8
11
9
## Features
12
-
- Supports Swift 3~> v0.2.0 and Swift 2 = v0.1.1
10
+
- Supports Swift 4~> v1.0.0, for Swift 3 use v0.3.4
13
11
- Synthaxic sugar and helper functions for common CoreBluetooth tasks
14
12
- Closure based CBCentralManager peripheral scanning with a timeout
15
13
- Notification based event for CBCentralManager state changes and state restoration
@@ -21,7 +19,7 @@ SwiftyBluetooth tries to address these concerns by providing a clear, closure ba
21
19
## Usage
22
20
The Library has 2 important class:
23
21
24
-
- The `Central` class, a Singleton wrapper around `CBCentralManager`mostly used to scan for peripherals with a closure callback.
22
+
- The `Central` class, a Singleton wrapper around `CBCentralManager` used to scan for peripherals with a closure callback and restore previous sessions.
25
23
- The `Peripheral` class, a wrapper around `CBPeripheral` used to call `CBPeripheral` functions with closure callbacks.
26
24
27
25
Note: The library is currently not thread safe, make sure to run your `Central` and `Peripheral` operations on the main thread.
@@ -57,17 +55,6 @@ peripheral.connect { result in
57
55
}
58
56
}
59
57
```
60
-
### Disconnecting from a peripheral
61
-
```swift
62
-
peripheral.disconnect { result in
63
-
switch result {
64
-
case .success:
65
-
break// You are now disconnected from the peripheral
66
-
case .failure(let error):
67
-
break// An error happened during the disconnection
68
-
}
69
-
}
70
-
```
71
58
### Reading from a peripheral's service's characteristic
72
59
If you already know the characteristic and service UUIDs you want to read from, once a peripheral has been found you can read from it right away like this:
73
60
@@ -97,10 +84,10 @@ peripheral.readValue(ofCharac: charac) { result in
97
84
### Writing to a Peripheral's service's characteristic
98
85
If you already know the characteristic and service UUID you want to write to, once a peripheral has been found, you can write to that characteristic right away like this:
### Listening to and receiving Characteristic update notifications
114
-
=======
115
99
### Receiving Characteristic update notifications
116
-
>>>>>>> e38dfdfb7686e99d983675988bc6228705919464
117
100
Receiving characteristic value updates is done through notifications on the default `NotificationCenter`. All supported `Peripheral` notifications are part of the `PeripheralEvent` enum. Use this enum's raw values as the notification string when registering for notifications:
118
101
```swift
119
102
// First we prepare ourselves to receive update notifications
0 commit comments