0
-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
NSData *data = characteristic.value;
uint8_t *array = (uint8_t*) data.bytes;
cadenceValue = [CharacteristicReader readUInt8Value:&array];
self.cadence.text = [NSString stringWithFormat:@"%d", cadenceValue];
});
}
如何获得节奏从BLE(蓝牙低功耗)器件迅速2。我无法找到确切的代码。对于此didUpdateValueForCharacteristic
调用委托方法。Cadence的
我NRF工具箱的代码,但它是在目标C或SWIFT 3,但我的项目是在迅速2。我试图使用桥接头调用客观的c方法,但它总是返回0节奏。
Swift 3示例代码的外观如何? – davidgyoung
获取有关bindMemory错误和指针对象中迅速2 //上didUpdateValueForCharacteristic 让数据= characteristic.value 变种阵列= UnsafeMutablePointer(不同诱变:(数据作为NSData的).bytes.bindMemory(到:UINT8。 self,capacity:data!.count)) self.cadenceValue = NORCharacteristicReader.readUInt8Value(ptr:&array) //方法。 静态FUNC readUInt8Value(PTR aPointer:INOUT UnsafeMutablePointer ) - > UINT8 { 让VAL = aPointer.pointee aPointer = aPointer.successor() 返回VAL } @davidgyoung –
Ved
@davidgyoung面临的问题,以上面的代码转换在swift 2中,问题是使用aPointer.pointee和bindMemory – Ved