The logic goes like this:
if (blueTooth is on){
performSegueToPageA
}
else{
performSegueToPageB
}
But I can't for the life of me figure out how to do it. First, there's these overly complex (and as far as Stack Overflow is to be believed, doesn't always work, depending on the iOS version or the wind direction) CBCentralManager
crap.
Second, how do I call and structure it in such a way that it will return a BOOL
value?
Let's assume I'm only going to target iOS7+.
Here's what I got so far:
login.h:
@interface bla bla blah <AmongOtherThings, CBCentralManagerDelegate>
@property (nonatomic, strong) CBCentralManager* blueToothManager;
login.m:
#import <CoreBluetooth/CoreBluetooth.h>
- (void)viewDidLoad {
[self detectBluetooth]
}
- (void)detectBluetooth
{
if(!self.blueToothManager)
{
// Put on main queue so we can call UIAlertView from delegate callbacks.
self.blueToothManager = [[[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
}
[self centralManagerDidUpdateState:self.blueToothManager]; // Show initial state
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
NSString *stateString = nil;
switch(_blueToothManager.state)
{
case CBCentralManagerStateResetting: stateString = @"The connection with the system service was momentarily lost, update imminent."; break;
case CBCentralManagerStateUnsupported: stateString = @"The platform doesn't support Bluetooth Low Energy."; break;
case CBCentralManagerStateUnauthorized: stateString = @"The app is not authorized to use Bluetooth Low Energy."; break;
case CBCentralManagerStatePoweredOff: stateString = @"Bluetooth is currently powered off."; break;
case CBCentralManagerStatePoweredOn: stateString = @"Bluetooth is currently powered on and available to use."; break;
default: stateString = @"State unknown, update imminent."; break;
}
NSLog(@"%@", stateString);
}
For reference, on the code, look here. Of note is that I had to add an underscore to blueToothManager.state
in centralManagerDidUpdateState
simply because the code wouldn't build without it.
As is, it works well enough. Now, how do I get it to return BOOL values?
I take it it's not as simple as substituting void
for BOOL
(which I tried).
Thanks.