Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/netguru/blueswift
Swift framework for easy connection with Bluetooth peripherals.
https://github.com/netguru/blueswift
bluetooth bluetooth-connection bluetooth-low-energy bluetooth-peripherals corebluetooth ios iphone swift
Last synced: 6 days ago
JSON representation
Swift framework for easy connection with Bluetooth peripherals.
- Host: GitHub
- URL: https://github.com/netguru/blueswift
- Owner: netguru
- License: mit
- Created: 2018-01-08T11:53:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-27T13:56:23.000Z (about 1 year ago)
- Last Synced: 2024-04-28T07:01:35.755Z (7 months ago)
- Topics: bluetooth, bluetooth-connection, bluetooth-low-energy, bluetooth-peripherals, corebluetooth, ios, iphone, swift
- Language: Swift
- Homepage:
- Size: 3.08 MB
- Stars: 165
- Watchers: 15
- Forks: 32
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
![](./logo.png)
![](https://img.shields.io/badge/swift-4.2-orange.svg)
![](https://img.shields.io/github/release/netguru/BlueSwift.svg)
![](https://img.shields.io/badge/carthage-compatible-green.svg)
![](https://img.shields.io/badge/cocoapods-compatible-green.svg)
![](https://app.bitrise.io/app/23a07b63b3f55f97/status.svg?token=Rt_2gKUavbR8LQ7PVuTbYg&branch=master)Easy to use Bluetooth open source library brought to you by Netguru.
π€ Probably the easiest way to interact with bluetooth peripherals π€## π€Ήπ»ββοΈ Features
- [x] Handles connection with remote peripherals.
- [x] Handles advertising an iPhone as Bluetooth LE peripheral.
- [x] Closure based read/write/notify requests.
- [x] Built in data conversion method with `Command` wrapper.## π² Connection:
Below you can find an easy code sample to connect to the peripheral.
Really thats all that is needed πΎπΎ```swift
let connection = BluetoothConnection.shared
let characteristic = try! Characteristic(uuid: "your_characteristic_uuid", shouldObserveNotification: true)
let service = try! Service(uuid: "your_service_uuid", characteristics: [characteristic])
let configuration = try! Configuration(services: [service], advertisement: "your_advertising_uuid")
let peripheral = Peripheral(configuration: configuration)
connection.connect(peripheral) { error in
// do awesome stuff
}
```## π‘ Advertisement:
Below you can find a code sample the setup the iPhone to advertise Bluetooth.
That's all it takes to advertise one service containing one characteristic.```swift
let characteristic = try! Characteristic(uuid: "your_characteristic_uuid")
let service = try! Service(uuid: "your_service_uuid", characteristics: [characteristic])
let configuration = try! Configuration(services: [service], advertisement: "your_service_uuid")
let peripheral = Peripheral(configuration: configuration, advertisementData: [.localName("Test"), .servicesUUIDs("your_service_uuid")])
advertisement.advertise(peripheral: peripheral) { error in
// oh no, something failed in that case
}
```## π π² Data transfer:
Of course data transfer is also possible, both for advertising and connection mode!
Below there are some basic examples, for more please see `More usage` section ππ»## Connection mode:
```swift
let command = Command.utf8String("Hello world")
peripheral.write(command: command, characteristic: someCharacteristic, handler: { error in
// written!
})
peripheral.read(characteristic, handler: { data, error in
// read!
})
```## Advertisement mode:
```swift
let command = Command.int8(3)
advertisement.update(command, characteristic: characteristic) { error in
// data updated!
}
advertisement.writeRequestCallback = { characteristic, data in
// written!
}
```## βοΈ More usage:
For more advanced usage check out documentation page at: https://netguru.github.io/BlueSwift/.
Also feel free to check example project bundled with this repository! π©πΌβπ« π¨πΌβπ«
It's a complete app that allows connection and sending text messages between two iPhones.## π Dependency management:
BlueSwift can be drag'n dropped to the project directory,
but what's more important it's supported by most common dependency management!### ![](https://img.shields.io/badge/cocoapods-compatible-green.svg)
Just drop the line below to your Podfile:
`pod 'BlueSwift'`
(but probably you'd like to pin it to the nearest major release, so `pod 'BlueSwift' , '~> 1.1.6'`)
### ![](https://img.shields.io/badge/carthage-compatible-green.svg)
The same as with Cocoapods, insert the line below to your Cartfile:
`github 'netguru/BlueSwift'`
, or including version - `github 'netguru/BlueSwift' ~> 1.1.6`
## π License
(As all cool open source software, it's...)
Licensed under MIT license.Also it would be really nice if you could drop us a line about your usage!! ππ