Swiftpack.co - netguru/BlueSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by netguru.
netguru/BlueSwift v1.0.0-alpha
Swift framework for easy connection with Bluetooth peripherals.
⭐️ 114
πŸ•“ 11 weeks ago
iOS
.package(url: "https://github.com/netguru/BlueSwift.git", from: "v1.0.0-alpha")


Easy to use Bluetooth open source library brought to you by Netguru.
🀟 Probably the easiest way to interact with bluetooth peripherals 🀟

πŸ€ΉπŸ»β€β™‚οΈ Features

  • β˜‘ Handles connection with remote peripherals.
  • β˜‘ Handles advertising an iPhone as Bluetooth LE peripheral.
  • β˜‘ Closure based read/write/notify requests.
  • β˜‘ 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 🍾🍾

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.

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:

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:

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!

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.1')

The same as with Cocoapods, insert the line below to your Cartfile:

github 'netguru/BlueSwift'

, or including version - github 'netguru/BlueSwift' ~> 1.1.1

πŸ“„ 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!! πŸš€πŸš€

GitHub

link
Stars: 114
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v1.1.1 (Delay Bluetooth authorization popup)
10 weeks ago

[1.1.1] - 2022-04-14

Added

  • bluetoothAuthorizationStatus public property was added to BluetoothConnection to determine current Bluetooth authorization status.
  • requestBluetoothAuthorization() public method was added to BluetoothConnection to requests User for authorization to use Bluetooth.
  • BluetoothAuthorizationStatus enum describing Bluetooth authorization status

Changed

  • ConnectionService: centralManager (CBCentralManager) is instantiated lazily to postpone showing Bluetooth authorization popup until it is needed.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics