bluetooth_connect 0.0.2 copy "bluetooth_connect: ^0.0.2" to clipboard
bluetooth_connect: ^0.0.2 copied to clipboard

Android / iOS BLE 扫描与连接。iOS 同时支持 CocoaPods 与 SPM(Swift Package Manager)依赖管理。

bluetooth_connect #

本地 Flutter 蓝牙(BLE)插件:支持 Android / iOS 扫描与连接。
iOS 同时支持 CocoaPods 与 SPM(Swift Package Manager)。(当前版本 0.0.2

本地开发(path 依赖) #

在宿主 App 的 pubspec.yaml 中:

dependencies:
  bluetooth_connect:
    path: ./plugins/bluetooth_connect
  # 或发布后:
  # bluetooth_connect: ^0.0.2

然后执行:

flutter pub get

功能 #

API 说明
isAvailable() 蓝牙硬件是否可用
isOn() 蓝牙是否开启
startScan() / stopScan() 开始 / 停止扫描
connect(deviceId) / disconnect() 连接 / 断开
scanResults 扫描结果流
connectionState 连接状态流

iOS:CocoaPods + SPM #

ios/
  bluetooth_connect.podspec
  bluetooth_connect/
    Package.swift
    Sources/bluetooth_connect/...

宿主开启 SPM:

flutter config --enable-swift-package-manager
flutter clean && flutter pub get
cd ios && pod install && cd ..
flutter run

权限配置(宿主 App 必配) #

Android #

插件已声明权限;Android 6+ / 12+ 会在扫描时动态申请。

iOS #

ios/Runner/Info.plist 增加:

<key>NSBluetoothAlwaysUsageDescription</key>
<string>需要蓝牙权限以扫描并连接设备</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>需要蓝牙权限以连接外设</string>

发布到 pub.dev #

  1. 注册 / 登录 pub.dev,并配置好 Google 账号
  2. 完善本插件 pubspec.yamlhomepage / repository(换成真实仓库地址)
  3. 确认 LICENSECHANGELOG.mdREADME.md 齐全
  4. 在插件根目录执行:
cd plugins/bluetooth_connect
flutter pub publish --dry-run   # 先检查
flutter pub publish             # 正式发布
  1. 发布成功后,其它项目可改为:
dependencies:
  bluetooth_connect: ^0.0.2

注意:包名 bluetooth_connect 在 pub.dev 上需唯一;若冲突请修改 name

示例 #

example/ 目录,或宿主工程中的「蓝牙连接」Demo 页。

1
likes
145
points
152
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Android / iOS BLE 扫描与连接。iOS 同时支持 CocoaPods 与 SPM(Swift Package Manager)依赖管理。

Repository (GitHub)

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on bluetooth_connect

Packages that implement bluetooth_connect