0

Is it possible to identify devices around me that have their bluetouth enabled? I don't need to communicate with them, just know they are there.

I am looking for something similar to android's BluetouthDevice.startDiscovery()

Is something like this possible?

Amit Raz
  • 5,370
  • 8
  • 36
  • 63
  • are you using xCode? Or a library like phonegap or titanium? – Rene Pot Oct 04 '11 at 07:16
  • @Topener I was planning to use xCode. What are phonegap or titaium? I need the app to be on the appstore, so only public api's for me :) – Amit Raz Oct 04 '11 at 07:21
  • Titanium is a JavaScript API, which compiles to objective-C, and thus is allowed in the app store. Same thing for phonegap, although you use HTML5,CSS & JavaScript there. And both are cross platform :) – Rene Pot Oct 04 '11 at 07:38
  • Maybe [this question](http://stackoverflow.com/questions/5715248/ios-how-to-perform-bluetooth-communication) could help bring some light. – Federico Zancan Oct 04 '11 at 07:39
  • @Topener I dont see how Titanium helps me to see if other users are around me and have their bluetouth enabled... can you explain more? We also need it to be cross platform between iphone and android. I read about gamekit but it seems to solve the problem only for ios devices... – Amit Raz Oct 04 '11 at 07:57
  • It really is important for the question, because we need to know in what language to support. But because you are building it in objective-C, the answer should also be in that language. Thus I added the objective-C tag to the question – Rene Pot Oct 04 '11 at 08:01

2 Answers2

4

Apple turns out to be very restrictive about Bluetooth communications for iOS platform.

Focusing about a native application with Xcode (but not PhoneGap based - PhoneGap is a Xcode plugin that allows web apps to be converted into native ones; btw it gives a quite nice but limited access to underlying hardware resources) for a iOS device to communicate with bluetooth devices (even with discovery actions) the following conditions have to be met:

-) The device you're trying to discover must be equipped with Apple Bluetooth authentication chip (you can ask to Apple directly for the MFi program);

-) Internally your app must declare a protocol name (e.g.: net.yourcompany.proto0) which the devices you connect with must conform to;

-) You must use Apple's External Accessory Framework to establish communication with such devices.

In short, by this procedure Apple guarantees that the only Bluetooth communications an iOS device can establish are just with authorized and certified Bluetooth devices.

I've gone 400 Mph about this thing but I hope it can give you some pointer to start your search.

The topic is too wide to be treated here in its full length.

Federico Zancan
  • 4,846
  • 4
  • 44
  • 60
1

One thing you might want to look into is Bonjour and NSNetServiceBrowser.

You can publish a service and also search for other services around you. There are ways to run Bonjour in the background (http://stackoverflow.com/questions/6345554/bonjour-in-the-background).

The only limitation with this approach is that everyone else would also need to be running the app as well. Also, by default Bonjour discovers over both WiFi and Bluetooth, something else you would probably need to look into.

Jonathan Ellis
  • 5,221
  • 2
  • 36
  • 53
  • I have read about bonjour but as far as I understood it needs all the devices to be connected to the same wifi network. Am I wrong? I have not seen an option to use bluetouth, can I have it use bluetouth and notify me about users around me? – Amit Raz Oct 04 '11 at 10:41
  • WiFi is not required to use Bonjour... it can also advertise a service on Bluetooth if Bluetooth on the device is enabled. I don't know if there's a way to choose to advertise on Bluetooth only, but it's possible that you could differentiate between Bluetooth and WiFi users when resolving NSNetServices. This isn't something I'm too sure on, but you can definitely use Bonjour over Bluetooth (it does this by default anyway). – Jonathan Ellis Oct 04 '11 at 11:54
  • So what you are saying is I can use Bonjour to query all peopel around me using my application? – Amit Raz Oct 04 '11 at 12:06
  • 1
    Yes and no. You can query anyone who is broadcasting a service. Does the iPhone broadcast some generic Bonjour services by default? I don't know... The best thing would be for you to broadcast your own service on each of the client devices (but that may not be what you want...) Either way: you are still going to encounter issues when trying to differentiate which devices have been discovered via Bluetooth and which have been discovered via WiFi... not sure of the best way to deal with that! – Jonathan Ellis Oct 04 '11 at 12:55
  • I dont care how it is discovered. is it cross platform? can I detect android devices as well? – Amit Raz Oct 04 '11 at 13:10