4

We are using the iOS private framework BluetoothManager for a simple experiment -- to find discoverable generic (non-iOS) BT devices within reach. Now, only the following line returns devices:

for(BluetoothDevice* device in [[BluetoothManager sharedInstance] pairedDevices])

Unfortunately it only returns devices already paired, which isn't quite what we want. Using connectingDevices instead of pairedDevices does not return any device at all. So, what options do we have to be able to detect any Bluetooth device within reach? I don't think I can use GameKit because I want to discover non-iOS devices.

Any suggestions are welcome.

Kar
  • 6,063
  • 7
  • 53
  • 82
  • 1
    I should clarify that I'm looking for a way to list nearby discoverable *generic* (non-iOS) devices. – Kar Jun 29 '11 at 14:38

3 Answers3

3

You need to use BluetoothManager to turn Bluetooth on, and then to enable bluetooth scanning of remote devices.

Having registered a notification callback, you will get the discovered devices. The notification object is actually a pointer to a BluetoothDevice object.

Get the BluetoothDevice object pointer, and from there you can get the name, address or connect to the remote device.

There is no RSSI here, you can see the complete list of methods by looking at the BluetoothDevice.h file.

I wrote a complete sample, compatible with iOS 5.1, here: http://www.pocketmagic.net/?p=2827

Good luck!

radhoo
  • 2,877
  • 26
  • 27
  • Have you ever updated this for recent iOS versions? As of iOS 8 or so, this doesn't seem to work any more. – Nate Jan 16 '16 at 12:58
  • Hi NAte, unfortunately I didn't have the time to revisit this recently. – radhoo Jan 17 '16 at 20:32
3

I've been messing with the private framework for a few days, and getting a list of nearby devices is pretty straightforward.

First, you have to enable device scanning using:

[[BluetoothManager sharedInstance] setDeviceScanningEnabled:YES];

If there are devices within range it will start posting BluetoothDeviceDiscoveredNotification notifications to the notification center. Subscribe to these and the object in the NSNotification delivered to the callback will be of type BluetoothDevice*.

I'm sure the BluetoothManager stores any discovered devices somewhere, but I just threw everything into my own NSMutableArray.

Unfortunately I still haven't figured out how to actually pair with a device using the private API.

Stoph
  • 693
  • 1
  • 5
  • 20
  • So, does that mean in order for an app to discover devices, it'd *have* to be jail-broken? – Kar Dec 14 '11 at 01:26
  • 2
    Nope, you just won't be able to submit your app to the store since Apple doesn't allow private frameworks. A good post for getting started using the framework is here: http://stackoverflow.com/a/1892077/1088502 – Stoph Dec 14 '11 at 15:18
  • From my understanding, the $99 dev program allows ad-hoc builds on the development phone. But if I were to distribute it to end users, would the users' phones need to be jailbroken? – Kar Dec 14 '11 at 15:25
  • I haven't tried distributing this yet, so I'm not certain, but I don't believe they would need to be jailbroken. Keep in mind, though, that because it's an unpublished API it may change at any point, so your app could break anytime the os updates. – Stoph Dec 14 '11 at 16:19
  • 1
    Yes, the $99 program allows you to create ad-hoc builds. However any device that runs it would need to be in the ad-hoc provision file. You can only have 100 devices registered in the provision portal. Not really an option for anything more than distributing to tester/reviewers, etc. – Craig B Aug 20 '12 at 03:29
-2

The GKSession class which is part of the GameKit framework is what you are looking for as it provides the ability to discover and connect to nearby iOS devices using Bluetooth.

werner
  • 859
  • 4
  • 8
  • But I think GK doesn't allow the list of discoverable devices within reach to be returned. Right? – Kar Jun 29 '11 at 12:46
  • yes you can : A GKSessionModeClient session searches for local devices advertising the same session ID. As it discovers available and compatible peers, it calls the delegate’s session:peer:didChangeState: method. The trick is to use GKSessionModeClient and GKSessionModeServer and stay away from GKSessionModePeer – werner Jun 29 '11 at 12:57
  • I think GKSession works if the discoverable devices are iOS devices, but not generic devices, right? – Kar Jun 29 '11 at 14:15
  • the question is about finding " discoverable generic (non-iOS) " . The game kit allows interacting with other iOS devices only. – radhoo Jul 16 '12 at 10:15