[英]How to change order of charateristics ID discovered while scanning peripheral using core bleutooth ios
I am using core bluetooth framework in ios and scanning and discovering 2 charateristics ID but i want their order to be different then what I am getting so is it possible to change their order or anything programmatically? 我在ios中使用核心蓝牙框架并扫描并发现2个charateristics ID,但我希望它们的顺序与我所得到的不同,因此可以通过编程方式更改其顺序或其他内容吗?
code 码
if (service.UUID.isEqual(CBUUID.UUIDWithString("F4F2-BC76-3206341A")))
{
println(service.characteristics.count)
for aChar:CBCharacteristic in service.characteristics as [CBCharacteristic]
{
println(aChar)
println(aChar.UUID)
/* Write data*/
if aChar.UUID.isEqual(CBUUID.UUIDWithString("D0F0AECD-6405-0B040047"))
{
var str:NSString = "heyaa..!!"
data = str.dataUsingEncoding(NSUTF8StringEncoding)!
peripheral.writeValue(data, forCharacteristic: aChar, type: CBCharacteristicWriteType.WithResponse)
println("Write performed")
}
/* read data */
if aChar.UUID.isEqual(CBUUID.UUIDWithString("C8853E-A248-C6F0B1"))
{
peripheral.readValueForCharacteristic(aChar)
println("Read performed")
}
}
}
In this characteristics ID for reading data is getting called first but i want to call write data characteristics ID first so is there any way to resolve. 在此特性ID中,用于读取数据的ID首先被调用,但是我想首先调用写入数据特性ID,因此有什么方法可以解决。 Please help me out.
请帮帮我。 Thank you in advance.
先感谢您。
The characteristics will be discovered in an arbitrary and undefined order, but that shouldn't matter. 将以任意且未定义的顺序发现特征,但这无关紧要。
You should store a reference to the discovered characteristics so that you can write to them as required. 您应该存储对发现的特征的引用,以便可以根据需要对其进行写入。
You app should go through distinct phases 您的应用程序应经历不同的阶段
For example: 例如:
var writeCharacteristic : CBCharacteristic?
var readCharacteristic : CBCharacteristic?
optional func peripheral(_ peripheral: CBPeripheral!, didDiscoverCharacteristicsForService service: CBService!,error error: NSError!) {
if (service.UUID.isEqual(CBUUID.UUIDWithString("F4F2-BC76-3206341A")))
{
println(service.characteristics.count)
for aChar:CBCharacteristic in service.characteristics as [CBCharacteristic]
{
println(aChar)
println(aChar.UUID)
/* Write data*/
if aChar.UUID.isEqual(CBUUID.UUIDWithString("D0F0AECD-6405-0B040047"))
{
self.writeCharacteristic=aChar
}
else if aChar.UUID.isEqual(CBUUID.UUIDWithString("C8853E-A248-C6F0B1"))
{
self.readCharacteristic=aChar
}
}
}
if (self.writeCharacteristic != nil && self.readCharacteristic != nil) {
var str:NSString = "heyaa..!!"
data = str.dataUsingEncoding(NSUTF8StringEncoding)!
peripheral.writeValue(data, forCharacteristic: self.writeCharacteristic!, type: CBCharacteristicWriteType.WithResponse)
println("Write performed")
}
}
optional func peripheral(_ peripheral: CBPeripheral!,didWriteValueForCharacteristic characteristic: CBCharacteristic!,error error: NSError!) {
peripheral.readValueForCharacteristic(self.readCharacteristic!)
println("Read performed")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.