测试已测试 | ✗ |
语语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2017年10月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Ismael Huerta 维护。
此库使用通知分派机制来接收数据。请从获取 MSBluetooth
的共享实例开始。
let bluetooth = MSBluetooth.sharedInstance
扫描会自动开始,因此请尽快调用此方法来开始侦听自行车。 MSBluetooth
会跟踪发现的设备,在一个元组的数组中(machineBroadcast: MSBLEMachineBroadcast, lastReceivedTime: Date)。您可以使用以下方法访问此数组
bluetooth.discoveredBikes
通知对象是 MSBluetooth
的一个实例,因此您可以访问您需要的任何公共变量。
当发现新设备时通知您。
NotificationCenter.default.addObserver(
forName: NSNotification.Name(MSBluetooth.BluetoothConnectionNotifications.BluetoothConnectionDidDiscoverMachine ),
object: bluetooth,
queue: queue)
{ notification in
self.discoveredMachine(notification: notification)
}
当设备不再传输数据时通知您。
NotificationCenter.default.addObserver(
forName: NSNotification.Name(MSBluetooth.BluetoothConnectionNotifications.BluetoothConnectionUpdateDiscoveredMachines ),
object: bluetooth,
queue: queue)
{ notification in
self.discoveredMachine(notification: notification)
}
要侦听特定自行车,只需在 MSBluetooth
上设置 focusedBikeId
并使用以下方式注册接收通知
NotificationCenter.default.addObserver(
forName: NSNotification.Name(MSBluetooth.BluetoothConnectionNotifications.BluetoothConnectionDidReceiveMachineBroadcast),
object: bluetooth,
queue: queue)
{ notification in
self.updateData(notification: notification)
}
notification.userInfor
包含一个 broadcast
键,它是 MSBLEMachineBroadcast
的一个实例。此对象包含来自自行车的解析数据。
MSeriesBle 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行
pod 'MSeriesBle'
MSeriesBle 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。