I hear that iOS7 introduced this functionality with CBCentralManager but can't find how. Is possible? There is another way widthout use GKPeerPickerController?
Asked
Active
Viewed 1.9k times
3 Answers
27
You can also set the CBCentralManagerOptionShowPowerAlertKey
key while instantiating the CBCentralManager
to true
. Then iOS will show the alert that "Turn On Bluetooth to Allow "Your App" to connect to Accessories". This alert will take you directly to the Bluetooth Setting page.
SampleCode In swift:
centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
SampleCode In Objective-C:
centralManager = [[CBCentralManager alloc]
initWithDelegate:self
queue:dispatch_get_main_queue()
options:@{CBCentralManagerOptionShowPowerAlertKey: @(YES)}];
Happy Coding.. :)

Sahil Mahajan
- 3,922
- 2
- 29
- 43
-
`CBCentralManagerOptionShowPowerAlertKey` is **true by default**. [CBCentralManagerOptionShowPowerAlertKey](https://developer.apple.com/documentation/corebluetooth/cbcentralmanageroptionshowpoweralertkey) – Kozmotronik Jun 14 '22 at 14:49
14
No, if the user has turned off Bluetooth all you can do is display an alert or message asking them to turn it on.
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
if (central.state == CBCentralManagerStatePoweredOff) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Error" message: @"Please turn on Bluetooth in Settings" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}

Paulw11
- 108,386
- 14
- 159
- 186
-
Just check the status of CBCentralManager `state` https://developer.apple.com/Library/ios/documentation/CoreBluetooth/Reference/CBCentralManager_Class/translated_content/CBCentralManager.html#//apple_ref/c/tdef/CBCentralManagerState for 'powered off' and display an alert – Paulw11 Sep 06 '14 at 07:57
-
I have already gone through it but i could not understand can u provide me sample code – Balaji Kondalrayal Sep 06 '14 at 08:00
-
-
Is there any any code to open iphone setting from the alert button – Balaji Kondalrayal Sep 06 '14 at 09:25
-
-
But in apps like whats app we can move to settings using alert view button even in ios7.0.6 – Balaji Kondalrayal Sep 06 '14 at 10:11
-
1Only system dialogs can open settings (in iOS 8 you will be able to open *your apps* settings). If I start my app that uses Bluetooth with Bluetooth turned off it displays a system alert that allows me to go to settings - see here http://stackoverflow.com/questions/12533269/ios-check-if-bluetooth-is-on-without-system-alert-popup-to-user – Paulw11 Sep 06 '14 at 10:14
-3
use bluetooth Manager framework,
import the bluetoothManager Framework, create a object of bluetooth manager framework, as btManager,
write the following code in Bluetooth On button target
[btManager setPowered:YES];
[btManager setEnabled:YES];
all the best...

John Weisz
- 30,137
- 13
- 89
- 132

Aman Gangurde
- 70
- 9
-
2This is a private API which will get your app rejected on the App Store. – Pedro Góes Jan 03 '17 at 20:55
-