Is NSNetService between a Mac and iOS device over Bluetooth only (WiFi off) possible?

I'm trying to sort out the system/hardward requirements for using Bonjour/NSNetService to connect an iPhone to a Mac.


Are these combinations possible:


  1. [?] Bluetooth ON, WiFi OFF on Mac and iPhone
  2. [?] Bluetooth OFF, WiFi ON on Mac and iPhone, but both devices are not part of any WiFi network (i.e. no router present)
  3. [✓ Works] Bluetooth OFF, WiFi On, Mac and iPhone part of the same WiFi network


I got a Bluetooth-only NSNetService up and running between an iPhone and an iPad, but never with a Mac (MacBook Pro mid-2012). Is this a hardware issue or is it not possible to connect an iPhone and a Mac through Bluetooth alone?


Thanks!


PS: I set includesPeerToPeer = true for the service and browser. My code is based on the WiTap sample code.

Answered by DTS Engineer in 116201022

The current situation is:

  • peer-to-peer Bluetooth

    • OS X — not supported

    • iOS — all relevant hardware and software releases

    • watchOS — not applicable

    • tvOS — not supported

  • peer-to-peer Wi-Fi

    • OS X — OS X 10.10 and later on relatively modern hardware (circa 2012 or later)

    • iOS — iOS 7.0 and later on all devices with a Lightning connector (it’s not tied to the Lightning hardware, it’s just a helpful coincidence)

    • watchOS — not applicable

    • tvOS — not working

Note:

  • watchOS does not support direct TCP connections (things like BSD Sockets and NSStream) for third-party apps, which makes the situation with peer-to-peer network interfaces irrelevant.

  • tvOS should support peer-to-peer Wi-Fi but the support is not functioning reliably right now (r. 24713937, r. 24713970).

Share and Enjoy

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

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

(r. 27821801)

Accepted Answer

The current situation is:

  • peer-to-peer Bluetooth

    • OS X — not supported

    • iOS — all relevant hardware and software releases

    • watchOS — not applicable

    • tvOS — not supported

  • peer-to-peer Wi-Fi

    • OS X — OS X 10.10 and later on relatively modern hardware (circa 2012 or later)

    • iOS — iOS 7.0 and later on all devices with a Lightning connector (it’s not tied to the Lightning hardware, it’s just a helpful coincidence)

    • watchOS — not applicable

    • tvOS — not working

Note:

  • watchOS does not support direct TCP connections (things like BSD Sockets and NSStream) for third-party apps, which makes the situation with peer-to-peer network interfaces irrelevant.

  • tvOS should support peer-to-peer Wi-Fi but the support is not functioning reliably right now (r. 24713937, r. 24713970).

Share and Enjoy

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

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

(r. 27821801)

Awesome, thanks a lot!!!

Is there a known workaround for tvOS wifi peer-to-peer not functioning reliably (or issues r. 24,713,937, r. 24,713,970 assuming they're the same thing)? We're communicating via sockets, so I'm hoping there's an easy workaround.


iOS and tvOS can discover each other and resolve their addresses, but when connecting it times out on the connect() function. It would be great to know if there's a solution in the meantime.

Dear Quinn, given that on tvOS 10 Multipeer Connectivity is now supported, does that mean that p2p bluetooth / wifi on tvOS 10 now should work?

Hello Quinn,


Can you please verify that P2P bluetooth still works in iOS 11? We cannot get it to work in our app or with WiTap! The remote device is never discovered.


(wi-fi direct does work however)


Thanks.

Can you please verify that P2P bluetooth still works in iOS 11?

It does not. This recently came up on the bonjour-dev mailing list. This post is the crux of it but the entire (relatively short) thread is worth reading.

ps That link is now broken so I’ve added a copy of the relevant bits in the following text attachment.

Subject: NSNetService Connection Priorities
From: David Carroll
Date: 15 Sep 2017

I am using the NSNetService and NSNetServiceBrowser to establish a
connection between two iPads.  However, I need the ability to better
control a connection and priority of the various connections between the
two iPads.    Specifically, I like a way to set the following connection
priority. 
1) Ad-hoc Wifi
    - This only works if the device is disconnected from the network
    - This does not seem to work on iPad-2 (9.3.5)
2) Ad-hoc Bluetooth
    - This does not work on iOS11
3) Wifi - network connected 
     - This appears to be Bonjour's current default network priority 

Unfortunately, I have looked through the API's and do not see a good way
using Bonjour and the NSNetService an NSNetServiceBrowser APIs. 

I don't want to have to rewrite and retest the entire connection
mechanism and verify that is works between all the various types of
iPads.  So I am looking for a way within NSNetServer and
NSNetServiceBrowser APIs to better control the connection.

So I am looking for a way to perform any of the following:
1) Prioritize connections using Bonjour
2) Detect the various connection types with Bonjour
3) Disable or ignore various connection within Bonjour

I'm looking at a way to perform this within
NSNetServiceBrowser:didFindService. 

Any thoughts or suggestions? 

David

                   *                   *                   *

From: Quinn "The Eskimo!"
Date: 15 Sep 2017

On 15 Sep 2017, at 12:39, David Carroll wrote:

> So I am looking for a way within NSNetServer and NSNetServiceBrowser
> APIs to better control the connection.

That's not possible with the NSNetService API.  The only control you
have there is whether to include peer-to-peer interfaces at all (via the
`includesPeerToPeer` property).  You can't control the resolution
priority.

You might be able to make some progress using the lower-level DNS-SD
API, <dns_sd.h>. This has separate knobs for the two different
peer-to-peer types.

If you do decide to investigate the DNS-SD API, check out the
DNSSDObjects sample code, which is an Objective-C wrapper around DNS-SD
that makes it easier for folks coming from NSNetService.

<https://developer.apple.com/library/content/samplecode/DNSSDObjects/>

> This does not seem to work on iPad-2 (9.3.5)

That's expected.  Peer-to-peer Wi-Fi requires a device with a Lightning
connector (the Lightning connected isn't actually relevant here, it's
just a happy coincidence that these two are correlated).

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

                   *                   *                   *

From: Jens Alfke
Date: 15 Sep 2017

On Sep 15, 2017, at 4:39 AM, David Carroll wrote:

> So I am looking for a way to perform any of the following:
> 1) Prioritize connections using Bonjour
> 2) Detect the various connection types with Bonjour
> 3) Disable or ignore various connection within Bonjour

In general, Bonjour is only responsible for discovering the service, not
for connecting to it. NSNetService does have a method to open a
connection, but (as I understand it) it's mostly a convenience that
first resolves the IP address and then calls NSStream to open a socket
to that address+port.

However, I'm not sure how this ties in with the OS's ability to connect
over Bluetooth or ad-hoc WiFi. I don't know if these connection modes
manifest as different IP addresses, or different network interfaces.

In other words, when a peer is reachable through two or more of the
modes you list, I don't know if resolving the NSNetService will show a
different IP address corresponding to each mode, and if so, whether it's
possible to choose one of those addresses and then connect to it and get
that mode. If so, it seems this would solve your problem. Quinn?

--Jens

                   *                   *                   *

From: Quinn "The Eskimo!"
Date: 15 Sep 2017

On 15 Sep 2017, at 17:04, Jens Alfke wrote:

> However, I'm not sure how this ties in with the OS's ability to
> connect over Bluetooth or ad-hoc WiFi.

Needless to say this is complex, but the short summary is that when you
resolve a Bonjour service discovered over peer-to-peer the system brings
up a peer-to-peer interface (if it's not up already) and from there
every runs like normal TCP/IP.

> In other words, when a peer is reachable through two or more of the
> modes you list, I don't know if resolving the NSNetService will show a
> different IP address corresponding to each mode ...

It won't, at least in the most common case of being able to see the
service over both peer-to-peer and infrastructure.  Bringing up a
peer-to-peer interface is expensive, so the system won't do it unless it
has to.

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

                   *                   *                   *

From: Quinn "The Eskimo!"
Date: 15 Sep 2017

[I didn't want to respond to the following until I receive positive
confirmation from the Bonjour team.]

On 15 Sep 2017, at 12:39, David Carroll wrote:

> 2) Ad-hoc Bluetooth
>    - This does not work on iOS11

Peer-to-peer Bluetooth is not supported on iOS 11 and friends.

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

                   *                   *                   *

From: Jens Alfke
Date: 15 Sep 2017

On Sep 15, 2017, at 9:30 AM, Quinn "The Eskimo!" wrote:

> Peer-to-peer Bluetooth is not supported on iOS 11 and friends.

Can you share any information on the reason for this regression? Like,
was it deemed unnecessary because ad-hoc WiFi works just as well, or was
it unreliable, or ... ?

(Also, does this apply to macOS 10.13? IIRC, TCP-over-BT work(ed) on
Macs too?)

--Jens

                   *                   *                   *

From: Quinn "The Eskimo!"
Date: 18 Sep 2017

On 15 Sep 2017, at 18:35, Jens Alfke wrote:

> Like, was it deemed unnecessary because ad-hoc WiFi works just as well
> ...

I'm not familiar with all the decision making but my understanding is
that the above was a big part of it.

> IIRC, TCP-over-BT work(ed) on Macs too?

Bluetooth peer-to-peer networking was never supported on macOS.

Share and Enjoy
--
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for your response. It's too bad this decision was made. There are still quite a bit of older devices that don't support wi-fi direct and use bluetooth for peer to peer connections.


Does the DNS-SD API support wi-fi direct? Last year in a post you mentioned that the only way to get peer to peer wi-fi is with NSNetService. We have been unable to get this working using the DNS-SD apis.


Thanks for your help.

Does the DNS-SD API support wi-fi direct?

To be clear, Apple’s Bonjour-based peer-to-peer Wi-Fi is not Wi-Fi Direct. They are very different beasts.

Last year in a post you mentioned that the only way to get peer to peer wi-fi is with NSNetService.

As far I know that’s still the case.

Share and Enjoy

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

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

Well, disabling P2P over Bluetooth will break connectivity when one iOS device is using another device's Personal Hotspot. At least it does at the moment (iOS 12). Is there anything that can be done on our end to solve that or it's just a result the deprecating connectivity via Bluetooth?


This is dissapointing as our app relied on Bluetooth in this particular use case...

Is NSNetService between a Mac and iOS device over Bluetooth only (WiFi off) possible?
 
 
Q