Reputation: 1965
I am working in data transferring using bluetooth from BLE device to peripheral hardware. 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? What will be maximum size of chunks for 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)
}
Upvotes: 1
Views: 1076
Reputation: 460
I'm guessing Jalek found his answer but for anyone else seeking the figures.
iOS 7 requests a 135 byte MTU (132 bytes data + 3 overhead).
iOS 8 requests a 158 byte MTU (155 bytes data + 3 overhead).
Obviously, it will depend on the other device whether these values are accepted or a lower value returned.
Upvotes: 2