您可以在这里找到一个示例项目
要开始追踪自行车,您需要创建一个实现了 KKManagerDelegate 的代理,然后初始化 KKManager
KKManager *manager = [[KKManager alloc] initWithDelegate:yourDelegateClass];
您可以立即开始扫描,但建议您在 bluetoothStateDidChange (您的代理) 中确保蓝牙状态为开启,并从那里调用它
- (void)bluetoothStateDidChange:(CBCentralManagerState)state withManager:(KKManager *)manager {
if(state == CBCentralManagerStatePoweredOn) {
[manager startScanningForBikes];
} else {
// There's many more [states to check for](https://developer.apple.com/library/IOs//documentation/CoreBluetooth/Reference/CBCentralManager_Class/index.html#//apple_ref/c/tdef/CBCentralManagerState) but this is a simple example.
}
}
您可以使用 [manager startScanningForBikes]
开始扫描,或者使用 [manager startSimulationWithBikes:aNumberOfBikes]
模拟自行车,两种情况下都会调用相同的方法更新。
bikeListUpdated
在找到自行车时被调用,并提供了它们的最新信息。建议您使用自行车 ID 识别给用户,但请确保在内部使用 UUID 进行唯一标识,因为自行车 ID 是由自行车所有者设置的。
然后您可以使用 [manager followBike:bikeObject]
跟踪自行车,然后 bikeListUpdated
将不再被调用,只针对该自行车调用 followedBikeDidUpdate
。
很简单!三个方法实现后,您就可以追踪一辆自行车了。当然,您可以通过从不跟踪自行车来追踪多辆自行车,但这可能有点过分。