iOS 5: programmatically turn bluetooth on and off
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 :(
CQM
Updated on June 08, 2022Comments
-
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 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 almost 12 yearsIt didn't used to be. <sigh>. Try developer.apple.com/library/ios/#documentation/CoreBluetooth/…
-
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 - over 8 yearsThis would better fit a comment than an answer