Any way to enable bluetooth programmatically on iOS7 +

I heard that iOS7 introduced this feature with CBCentralManager but cannot find it. Maybe? Is there another way to use the width of the GKPeerPickerController?

+4
source share
3 answers

No, if the user has turned off Bluetooth, all you can do is show a warning or a message asking you 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]; 
    }
 }
+11
source

CBCentralManagerOptionShowPowerAlertKey CBCentralManager true. iOS , " Bluetooth, " " ". Bluetooth.

SampleCode :

centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])

SampleCode Objective-C:

centralManager = [[CBCentralManager alloc]
                                      initWithDelegate:self 
                                      queue:dispatch_get_main_queue() 
                                      options:@{CBCentralManagerOptionShowPowerAlertKey: @(YES)}];

..:)

+19

bluetooth Manager,

bluetoothManager Framework, bluetooth manager framework, btManager,

Bluetooth On

[btManager setPowered:YES];
[btManager setEnabled:YES];

...

-2

Source: https://habr.com/ru/post/1541799/


All Articles