iOS 5: programmatically turn bluetooth on and off

11,500

Solution 1

CoreBluetooth is publicly available in iOS 5. Unfortunately it only works for new Bluetooth LE (Low Energy) devices.

See CoreBluetooth Documentation

Solution 2

This is not public. You will get rejected.

Solution 3

According to the iOS 5.0 Release Notes there is no mention of any Bluetooth functionality being publicly available.

Solution 4

I needed to enable bluetooth programmatically. What I did was use the GKPeerPickerController, this asks you to enable bluetooth if it's not already on. Then on a call for the GKPeerPickerControllerDelegate I dismiss the picker.

Not perfect, you will see the "Searching for devices" for a short time, but It works in lack of another way of doing this (as far as I know).

GKPeerPickerController * peerpicker = [[GKPeerPickerController alloc]init];
peerpicker.delegate = self;
peerpicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[peerpicker show];

When the peerpicker is ready to search there's a delegate method to return a GKSession for the picker to use. This is where you dismiss it.

-(GKSession*)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type
{
    [picker dismiss];
    [picker autorelease];
    return nil;
}

And your app won't get rejected.

Solution 5

No, bluetooth is still not available :(

Share:
11,500
CQM
Author by

CQM

Updated on June 08, 2022

Comments

  • CQM
    CQM almost 2 years

    I saw that programmatically turning bluetooth on and off was a "private api" thing in previos versions of iOS that would get an app rejected from the apple itunes store.

    But in iOS 5, I am aware of previously private things that are no longer private, such as programmatically changing screen brightness. Doing this will no longer get your app rejected in itunes with iOS 5, so I am wondering if this other things were available publicly, like the bluetooth adapter.

  • whatchamacallit
    whatchamacallit almost 12 years
    "Public" and "Rejected" are two different things. If there is an API for this then it is public. Apple may reject your app based on how you are using it.
  • EricS
    EricS almost 12 years
  • Lily Ballard
    Lily Ballard almost 12 years
    @whatchamacallit: Except there is no API for the System Preferences setting that controls whether Bluetooth is enabled or disabled. EricS's PDF is about how to use Bluetooth LE in iOS 5, not how to turn Bluetooth on/off.
  • Ky -
    Ky - over 8 years
    This would better fit a comment than an answer