Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1amageek/Bleu
BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.
https://github.com/1amageek/Bleu
bluetooth bluetooth-le bluetooth-low-energy ios swift
Last synced: 3 months ago
JSON representation
BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.
- Host: GitHub
- URL: https://github.com/1amageek/Bleu
- Owner: 1amageek
- License: mit
- Created: 2017-03-13T12:25:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-10T10:26:35.000Z (over 5 years ago)
- Last Synced: 2024-11-24T16:42:50.648Z (3 months ago)
- Topics: bluetooth, bluetooth-le, bluetooth-low-energy, ios, swift
- Language: Swift
- Homepage:
- Size: 500 KB
- Stars: 492
- Watchers: 12
- Forks: 31
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-ios - Bleu - BLE (Bluetooth LE) for U. (Hardware / Bluetooth)
- awesome-ios-star - Bleu - BLE (Bluetooth LE) for U. (Hardware / Bluetooth)
README
# Bleu
Bleu is a Bluetooth library.
Bleu is the easiest way to operate CoreBluetooth.Bleu is possible to operate by replacing Bluetooth 's `Peripheral` and `Central` with `Server` and `Client`.
Bleu can be developed event-driven.[](http://cocoapods.org/?q=Bleu)
[](https://cocoapods.org/pods/Bleu)
[](https://github.com/sindresorhus/awesome)
[](https://cocoapods.org/pods/Bleu)## Installation
#### [CocoaPods](https://github.com/cocoapods/cocoapods)
- Insert `pod 'Bleu' ` to your Podfile.
- Run `pod install`.Note: CocoaPods 1.1.0 is required to install Bleu.
## UsagePlease customize `Communicable+.swift`.
``` shell
uuidgen // create uuid
`````` Swift
extension Communicable {
public var serviceUUID: CBUUID {
return CBUUID(string: "YOUR UUID")
}
}struct GetUserIDItem: Communicable {
public var method: RequestMethod {
return .get(isNotified: false)
}
public var characteristicUUID: CBUUID {
return CBUUID(string: "YOUR UUID")
}
}struct PostUserIDItem: Communicable {
public var method: RequestMethod {
return .post
}
public var characteristicUUID: CBUUID {
return CBUUID(string: "YOUR UUID")
}
}```
### 😃 Get
#### Peripheral(Server)
``` Swift
Bleu.addReceiver(Receiver(GetUserID(), get: { [weak self] (manager, request) in
guard let text: String = self?.textField.text else {
manager.respond(to: request, withResult: .attributeNotFound)
return
}
request.value = text.data(using: .utf8)
manager.respond(to: request, withResult: .success)
}))Bleu.startAdvertising()
```#### Central(Client)
``` Swift
let request: Request = Request(communication: GetUserID()) { [weak self] (peripheral, characteristic, error) in
if let error = error {
debugPrint(error)
return
}
let data: Data = characteristic.value!
let text: String = String(data: data, encoding: .utf8)!
self?.centralTextField.text = text
}
Bleu.send([request]) { completedRequests, error in
if let error = error {
print("timeout")
}
}
```### 😃 Post
#### Peripheral(Server)
``` Swift
Bleu.addReceiver(Receiver(PostUserID(), post: { (manager, request) in
let data: Data = request.value!
let text: String = String(data: data, encoding: .utf8)!
print(text)
manager.respond(to: request, withResult: .success)
}))Bleu.startAdvertising()
```#### Central(Client)
``` Swift
let data: Data = "Sample".data(using: .utf8)!
let request: Request = Request(communication: PostUserID()) { (peripheral, characteristic, error) in
if let error = error {
debugPrint(error)
return
}
print("success")
}
request.value = data
Bleu.send([request]) { completedRequests, error in
if let error = error {
print("timeout")
}
}
```