After upgrading to iOS 10, chat over Bluetooth using Bonjour does not work anymore.

I have an app that can browse for Bonjour published services and join to Bonjour services in order to exchange data. It has been working well, using Bluetooth, until it stopped working in iOS 10. It still works fine using WiFi but, in BT, it only sees the published services but they can not exchange data. We are also obtaining the same behavior with a different app that uses DNS-SD API to make the communication channel.


You can confirm this behaviour trying Chatty (code found in Github) but taking into account to set the includesPeerToPeer property on both sides (as mentioned in Technical Q&A QA1753)

If you download the BT Chat HD app from the App Store, it is the same. It works for iOS9 but not for iOS 10.0.2.


Is someone else experiencing the same?

Accepted Reply

Can you reproduce the problem with the WiTap sample code. For example:

  1. build the sample

  2. on two devices, disable Wi-Fi and enable Bluetooth

  3. run the app on both

  4. try to start a ‘game’

If so, I’d call that a bug and you should file it as such. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

Can you reproduce the problem with the WiTap sample code. For example:

  1. build the sample

  2. on two devices, disable Wi-Fi and enable Bluetooth

  3. run the app on both

  4. try to start a ‘game’

If so, I’d call that a bug and you should file it as such. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks eskimo for your help! WiTap works well for both WiFi and BT in iOS 9 and 10. I guess I was using really old code. The description of WiTap can not be clearer.


Thank you!

Hi Eskimo,


I have modified the connection in my code in order to use NSNetServices instead of <dns_sd.h> which was the way the app was using to connect over BT/WiFi. Now, both connections work well but I noticed the following:


- In BT, it takes a lot of time by the browser to tell that the NSNetservice of the other party was unpublished.

- In BT, the speed of the connection is slower than WiFi's. I use a slider in one device and when I stop moving the slider it takes like "2 seconds" for the other end to tell that I have sent the last package. I mean, there seems to be 2 seconds delay between when I send one message from one device to the other tell that it was received. This was not happening in iOS 9 with the low level implementation.


Do you know if there is anything I can do to make it better?

Thank you.

This was not happening in iOS 9 with the low level implementation.

How does your new implementation work on iOS 9?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for your help Eskimo.

The behaviour of my app is exactly the same both on iOS 9 and iOS 10. WiFi works well but the Bluetooth does not. To sum up:


- Same implementation but using the low level API (DNS_SD) works well both on BT and WiFi (iOS 9).

- The low level API does not work on iOS 10 using BT. It works well using WiFi.

- Same implementation using NSNetServices and NSStreams works well using WiFi and iOS9 / iOS10.

- Same implementation using NSNetServices and NSStreams does not work well using BT and iOS9 / iOS10. The throughput is really low compared to how it was using DNS_SD.


I use a slider in one side and I see the changes in the other side.


What could I do? Am I missing something?

  • Same implementation but using the low level API (DNS_SD) works well both on BT and WiFi (iOS 9).

  • The low level API does not work on iOS 10 using BT. It works well using WiFi.

I’m not sure whether you’re referring to infrastructure Wi-Fi or peer-to-peer Wi-Fi here. To be clear, the only supported way to get Bonjour over peer-to-peer Wi-Fi working is via NSNetService, and specifically the

NSNetServiceListenForConnections
feature.

Same implementation using NSNetServices and NSStreams does not work well using BT and iOS9 / iOS10. The throughput is really low compared to how it was using DNS_SD.

I’ve heard unconfirmed reports of some odd behaviour with Bonjour over Bluetooth on iOS 10. However, that’s new in iOS 10, and this problem reproduces in iOS 9. It’s hard to say what’s going on here but you can investigate it using the instructions in this post.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello Eskimo,


We have finally reached a solution to our issue and it comes from the difference between BT and WiFi. Let me tell you how we concluded this. We placed some NSLogs to see how the bytes were received in each mode: WiFi and BT, in WiTap and the package size was of 500 as it is for our apps. The thing is that in WiFi, the bytes are received in an ordered way: 99 % of the times we receive a message of 500 bytes each time NSStreamDelegate is called and the other 1% is just that NSInput had two packages in the same call. This is the same for iOS 9 and iOS 10. For Bluetooth, the things are completely different. The message is sent by chunks and the size of such chunks is truly random. Let's say, for a message size of 500, the message was divided into chunks, not always in a fraction of the whole message. This is really worse in iOS 10 than iOS 9. In order to fix this, we have to have this in NSStream Delegate:


case NSStreamEventHasBytesAvailable: {

NSInteger bytesRead;

UInt8 buf[1024*2];

while ([self.inputStream hasBytesAvailable])

{

bytesRead = [self.inputStream read:buf maxLength:sizeof(buf)];

if (bytesRead <= 0) {

//Do Nothing

} else {

//Append bytes to be read later

}

}

//Try to read what it got.

} break;


We think as we have another high consuming processes running at the same time, the next call to the Delegate would cause such delays. That is because there was more there to be read.


Apart from this, everything seems to be working well now.


Thanks for your hep!

FYI This issue appears to be fixed in iOS 10.2 beta 3. Can anyone else confirm?

FYI This issue appears to be fixed in iOS 10.2 beta 3. Can anyone else confirm?

Since my 9 Oct post on this thread I’ve learnt more about this issue. You can get the latest news from this other thread.

As always, if a particular fix is important to you, I encourage you to verify the fix for yourself and then file a new bug if you’re still having problems.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"