简体   繁体   English

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

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

I am working in data transferring using bluetooth from BLE device to peripheral hardware. 我正在使用蓝牙将数据从BLE设备传输到外围硬件。 I want to write data from binary file in chunks as total data length is 143233. I found one line "Maximal MTU was 132 bytes for iOS 7 devices and 20 B for iOS 6" but what about iOS 8? 我想从二进制文件中分块写入数据,因为总数据长度为143233。我发现一行“ iOS 7设备的最大MTU为132字节,iOS 6设备的最大MTU为20 B”,但是iOS 8呢? What will be maximum size of chunks for iOS 8? iOS 8的最大块大小是多少? This is the code which I have used, I dont know whether i am going right way or not so help me and guide me if i am going wrong. 这是我使用过的代码,我不知道我是否往正确的方向走,所以如果我走错了,请帮助我并指导我。 Thanks in advance. 提前致谢。

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)
 }

I'm guessing Jalek found his answer but for anyone else seeking the figures. 我猜Jalek找到了答案,但对于其他寻求这些数字的人来说。

iOS 7 requests a 135 byte MTU (132 bytes data + 3 overhead). iOS 7请求135字节的MTU(132字节数据+ 3开销)。

iOS 8 requests a 158 byte MTU (155 bytes data + 3 overhead). iOS 8请求158字节的MTU(155字节数据+ 3开销)。

Obviously, it will depend on the other device whether these values are accepted or a lower value returned. 显然,是否接受这些值或返回较低的值将取决于其他设备。

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

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