繁体   English   中英

在iOS 8中使用蓝牙发送到外围设备的数据量

[英]Amount of data to be sent to peripheral using bluetooth in ios 8

我正在使用蓝牙将数据从BLE设备传输到外围硬件。 我想从二进制文件中分块写入数据,因为总数据长度为143233。我发现一行“ iOS 7设备的最大MTU为132字节,iOS 6设备的最大MTU为20 B”,但是iOS 8呢? iOS 8的最大块大小是多少? 这是我使用过的代码,我不知道我是否往正确的方向走,所以如果我走错了,请帮助我并指导我。 提前致谢。

var count:Int = 0
var counter:Int = 0
var str:NSString = NSBundle.mainBundle().pathForResource("spp", ofType: "bin")!
println("string value is \(str)")     
var dataFile:NSString = NSString.stringWithContentsOfFile(str, encoding: NSASCIIStringEncoding, error: nil)
data = dataFile.dataUsingEncoding(NSUTF8StringEncoding)
println(data!.length)
println(dataFile.length)
var dataLen:Int = data!.length
if (dataLen > 132)
   {
      while(count < dataLen && dataLen - count > 132)
        {
          peripheral.writeValue(data!.subdataWithRange(NSMakeRange(count, 132)), forCharacteristic: arrCharacteristics!.objectAtIndex(1) as CBCharacteristic , type: CBCharacteristicWriteType.WithResponse)
           NSThread.sleepForTimeInterval(0.005)
           println("Write performed \(counter++ )")
                   count += 132
                }
            }   if (count < dataLen)
 {
   peripheral.writeValue(data!.subdataWithRange(NSMakeRange(count, dataLen - count)), forCharacteristic: arrCharacteristics!.objectAtIndex(1) as CBCharacteristic , type: CBCharacteristicWriteType.WithResponse)
 }

我猜Jalek找到了答案,但对于其他寻求这些数字的人来说。

iOS 7请求135字节的MTU(132字节数据+ 3开销)。

iOS 8请求158字节的MTU(155字节数据+ 3开销)。

显然,是否接受这些值或返回较低的值将取决于其他设备。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM