Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Swift framework for easy connection with Bluetooth peripherals.

License

NotificationsYou must be signed in to change notification settings

netguru/BlueSwift

Repository files navigation


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 withCommand wrapper.

📲 Connection:

Below you can find an easy code sample to connect to the peripheral.
Really thats all that is needed 🍾🍾

letconnection=BluetoothConnection.sharedletcharacteristic=try!Characteristic(uuid:"your_characteristic_uuid", shouldObserveNotification:true)letservice=try!Service(uuid:"your_service_uuid", characteristics:[characteristic])letconfiguration=try!Configuration(services:[service], advertisement:"your_advertising_uuid")letperipheral=Peripheral(configuration: configuration)connection.connect(peripheral){ errorin// 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.

letcharacteristic=try!Characteristic(uuid:"your_characteristic_uuid")letservice=try!Service(uuid:"your_service_uuid", characteristics:[characteristic])letconfiguration=try!Configuration(services:[service], advertisement:"your_service_uuid")letperipheral=Peripheral(configuration: configuration, advertisementData:[.localName("Test"),.servicesUUIDs("your_service_uuid")])advertisement.advertise(peripheral: peripheral){ errorin// 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 seeMore usage section 👇🏻

Connection mode:

letcommand=Command.utf8String("Hello world")peripheral.write(command: command, characteristic: someCharacteristic, handler:{ errorin// written!})peripheral.read(characteristic, handler:{ data, errorin// read!})

Advertisement mode:

letcommand=Command.int8(3)advertisement.update(command, characteristic: characteristic){ errorin// data updated!}advertisement.writeRequestCallback={ characteristic, datain// 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, sopod 'BlueSwift' , '~> 1.1.6')

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!! 🚀🚀


[8]ページ先頭

©2009-2025 Movatter.jp