I am using GameKit.framework for implementing Bluetooth in my app, but in didLoad I want to check if Bluetooth is turned on or turned off. Could anybody tell me how to do this?
Asked
Active
Viewed 201 times
0
-
1possible duplicate of [Checking Bluetooth Status](http://stackoverflow.com/questions/6494664/checking-bluetooth-status) – Joachim Isaksson Feb 16 '13 at 05:56
2 Answers
2
There's a private framework called BluetoothManager
which can get the status easily. However, if you use it, your app will probably be rejected from the app store. So, only use this for apps you intend to distribute some other way.
Include this header in your project. Then you may write:
#import "BluetoothManager/BluetoothManager.h"
BluetoothManager *bt;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
bt = [[BluetoothManager alloc] init];
}
- (BOOL)getBluetoothEnabled {
return [bt enabled];
}
Then, you just call getBluetoothEnabled
.

nneonneo
- 171,345
- 36
- 312
- 383
-
+1. This is the correct answer. "It's impossible" is rarely true (how people think jailbreak tweaks and apps do stuff?)... – Feb 16 '13 at 06:10
-
What irritates me is that this framework has been around long enough for Apple to at least expose *part* of this functionality. For them not to expose something as simple as "is Bluetooth enabled?" is shameful in my books. (Probably why I quit doing iOS development). – nneonneo Feb 16 '13 at 06:12
-
Exactly. Agreed. (I'm wondering what I will do once iOS N is released and can't be jailbroken... Will I switch to Android or what? But c'mon, it's crap!) – Feb 16 '13 at 06:15
-
it is giving me error Lexical or Preprocessor Issue and 'BluetoothManager/BluetoothManager.h' file not found – Jaspreet Singh Feb 16 '13 at 06:24
-
Well...you need to take the header I linked and put it in a `BluetoothManager/` subfolder... – nneonneo Feb 16 '13 at 06:26
-
can you please test it create project and add these files in your project and then #import "BluetoothManager/BluetoothManager.h" after that it will show the error – Jaspreet Singh Feb 16 '13 at 06:34
-
I tested it. It works, though you do need to make sure to link in the `BluetoothManager` private framework from `/Applications/Xcode.app/Contents/Developer/SDKs/
/System/Library/PrivateFrameworks/BluetoothManager.framework`. Sorry if that wasn't clear. – nneonneo Feb 16 '13 at 07:03 -
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24609/discussion-between-jaspreet-singh-and-nneonneo) – Jaspreet Singh Feb 16 '13 at 07:45
0
You can't check with the current SDK. There is no Public API available for this.

Maulik
- 19,348
- 14
- 82
- 137
-
Well, no *public* API. `BluetoothManager` has been able to do this for a while. – nneonneo Feb 16 '13 at 05:58
-
@nneonneo How it will be possible by BluetoothManage can you explain me and provide me code or link – Jaspreet Singh Feb 16 '13 at 06:01
-
As it is a private framework, you won't be able to submit to the app store. If you're OK with that, I will post the answer. – nneonneo Feb 16 '13 at 06:01
-
There is a way on iOS 5 and above using CoreBluetooth. The class you can use is CBCentralManager. It has a property 'state' that you can check to see if Bluetooth is on or not. (the enum CBCentralManagerState has the value(s) you want to check against). – Pushpak Narasimhan Feb 16 '13 at 06:08
-
@PushpakNarasimhan: This has the disadvantage of popping up a dialog box if Bluetooth is not enabled. You cannot suppress the dialog AFAIK. – nneonneo Feb 16 '13 at 06:11