I need some sample code to see how to transfer an audio file (or any other binary data) using CoreBlueTooth L2CAP channel. Assuming the file is not so small, let us say it is a few hundred kilobytes.
I am working on a small iOS app doing that, but it is only working half way.
At this point I can transfer a few thousand bytes, but it does not go further.
Just in case, this is the related code I have on the sending side:
let path = Bundle.main.path(forResource: "\(name)", ofType: nil)!,
url = URL(fileURLWithPath: path)
do {let audioData = try Data(contentsOf: url)
// do something useful with audioData to send it
// to the other device.
..........
let bytesWritten = data.withUnsafeBytes {outStream!.write($0, maxLength: audioData.count)}
if bytesWritten > 0 {
..........
}
} catch {
print("Error: \(error.localizedDescription)")
}
On the receiving side:
let inData = Data(reading: inStream)
if inData.count != 0 {
// Data has been received.
.......
}
I am obviously not showing much detail, but my code is missing some critical parts anyway, this is why I would be glad to find some little working sample in order to see how it works.