Concept2-SDK 0.2.0

Concept2-SDK 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2015年11月
SPM支持 SPM

jessecurry 维护。



用法

要运行示例项目,请克隆存储库,然后首先从 Example 目录中运行 pod install

要求

安装

Concept2-SDK 可通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile 中

pod "Concept2-SDK"

用法

请参考 iOS 示例以获取完整实现

导入 SDK

import Concept2_SDK

Concept2_SDK 使用 Subject 提供值变更的通知。将 isReady 属性附加到 BluetoothManager 单例上。

var isReadyDisposable:Disposable?
var performanceMonitorsDisposable:Disposable?

// ...

isReadyDisposable = BluetoothManager.isReady.attach {
  [weak self] (isReady:Bool) -> Void in
  // Do something when the manager is ready, usually enable the UI
}

performanceMonitorsDisposable = BluetoothManager.performanceMonitors.attach {
  [weak self] (performanceMonitors) -> Void in
  // Do something with the performance monitors, usually display to the user or connect
}

开始扫描性能监控器(它们需要处于范围内并且无线开)

BluetoothManager.scanForPerformanceMonitors()

当找到性能监控器时,BluetoothManager 上的 performanceMonitors 观察者将被通知,此时您可以连接到性能监控器之一

// You'll want to stop scanning to save power
BluetoothManager.stopScanningForPerformanceMonitors()

// Then connect to
let pm:PerformanceMonitor = performanceMonitors[indexOfMonitor]
BluetoothManager.connectPerformanceMonitor(pm)

PerformanceMonitor 有自己的可观察属性集。在这个时候,连接的监控器将自动注册以接收所有蓝牙特征更改事件的通知。在未来,只有您表示兴趣的属性才会被标记为特征更改事件。

将您感兴趣的属性附加,您的回调将在附加时调用一次,然后每当观察属性的值发生变化时。

var strokesPerMinuteDisposable:Disposable?
var distanceDisposable:Disposable?

// ...

strokesPerMinuteDisposable = performanceMonitor?.strokeRate.attach({
  [weak self] (strokeRate:C2StrokeRate) -> Void in
  if let weakSelf = self {
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
      weakSelf.strokesPerMinuteLabel.text = "\(strokeRate)"
    })
  }
})

distanceDisposable = performanceMonitor?.distance.attach({
  [weak self] (distance:C2Distance) -> Void in
  if let weakSelf = self {
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
      weakSelf.distanceLabel.text = "\(distance)"
    })
  }
})

现在您应该能够看到流着的值。

作者

jessecurry, [email protected]

许可证

Concept2-SDK 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。