[英]IOS Write to BLE Characteristic using Slider
真正努力回寫BLE外圍設備。 請幫忙...
我已連接並閱讀了可用的特性,並希望從IBAction滑塊回寫:
-(IBAction)SrControlIndex:(UISegmentedControl *)sender
{
switch (_SRControl.selectedSegmentIndex)
{
case 0:
[self writeModeCharacteristic:Status_UUID data:[@"00" dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"First Sel");
break;
case 1:
NSLog(@"Second Sel");
break;
default:
break;
}
}
並調用以下代碼:
-(void)writeModeCharacteristic:(CBCharacteristic *)ModeCharacteristic data:(NSData*)data
{
[ModeCharacteristic.service.peripheral writeValue:data forCharacteristic:ModeCharacteristic type:CBCharacteristicWriteWithResponse];
}
我想念什么?
感謝Larme的回答:
@屬性(非原子的,強的)CB特征狀態特征; 當您發現它時:_statusCharacteristic = statusCharacteristicJustDiscovered; 然后,您可以在您的方法中重用它。
這很棒...
一種選擇是保留CBPeripheral
對象。 在檢測服務和特征之后,您可以運行以下命令:
for (CBService *service in self.peripheral.services) {
if ([service.UUID isEqual:[CBUUID UUIDWithString:@"YOUR-SERVICE-UUID"]]) {
for (CBCharacteristic *characteristic in service.characteristics) {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"YOUR-CHARACTERISTIC-UUID"]]) {
[self.peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.