1

I implemented the centralManagerDidUpdateState function which somehow does not fire the CBCentralManagerStateUnauthorized state. If I switch off the Bluetooth Sharing option for the App in Settings, it still shows CBCentralManagerStatePoweredOn state after restarting the App. If I switch the BT Sharing Setting OFF or ON, when the App is running in the background, it even crashes the App with an error which I can't debug. (-> SIGKILL). All delegates are set correctly...

Does anyone know why it crashes and why the function does not detect the Settings correctly?

This is the code:

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    switch (central.state) {
        case CBCentralManagerStatePoweredOff: {
            NSLog(@"CoreBluetooth BLE hardware is powered off");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"OFF"];
            [[NSUserDefaults standardUserDefaults] setObject:@"OFF" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStatePoweredOn: {
            NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"ON"];
            [[NSUserDefaults standardUserDefaults] setObject:@"ON" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateResetting: {
            NSLog(@"CoreBluetooth BLE hardware is resetting");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"RESETTING"];
            [[NSUserDefaults standardUserDefaults] setObject:@"RESETTING" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateUnauthorized: {
            NSLog(@"CoreBluetooth BLE state is unauthorized");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNAUTHORIZED"];
            [[NSUserDefaults standardUserDefaults] setObject:@"UNAUTHORIZED" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateUnknown: {
            NSLog(@"CoreBluetooth BLE state is unknown");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNKNOWN"];
            [[NSUserDefaults standardUserDefaults] setObject:@"UNKNOWN" forKey:@"beaconPowerStatus"];
            break;
        }
        case CBCentralManagerStateUnsupported: {
            NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"beaconPowerStatus" object:@"UNSUPPORTED"];
            [[NSUserDefaults standardUserDefaults] setObject:@"UNSUPPORTED" forKey:@"beaconPowerStatus"];
            break;
        }
        default:
            break;
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
}
Peter
  • 183
  • 2
  • 12
  • 1
    Install an uncaught exception handler as described in this post: http://stackoverflow.com/a/7896769/768935 Otherwise, use break points in xcode to figure out what's going wrong. It's not enough info you shared to diagnose your issue. – allprog Mar 11 '14 at 13:09
  • Thanks, I implemented the code, but there is no exception to handle. The App terminates with (lldb) displayed in blue in the debugger window and this line of code is highlighted green: return UIApplicationMain(argc, argv, nil, NSStringFromClass([PEKAppDelegate class])); with the comment: Thread 1: signal SIGKILL. This happens after I installed the App, put it into background, going to settings and switch on or off bluetooth sharing for the app. Also, even though I switch off bluetooth sharing the state UNAUTHORIZED is never shown. – Peter Mar 11 '14 at 20:45
  • 1
    Have you set the background mode bluetooth-central? If not, then this may be an unexpected consequence and should be reported to Apple. Bluetooth sharing is only for the peripheral manager stuff. I don't remember ever seeing unauthorized for central manager. – allprog Mar 11 '14 at 21:36
  • Aha! You are of course totally right. I looked into the iBeacon examples (and nothing more I want to use) and the example App is not listed in the Bluetooth Sharing list (where e.g. the Pebble App is listed). I removed all Target Capabilities in Xcode for my App but still it is listed in the Bluetooth Sharing list. Perhaps you can answer me, which causes this entry? Thanks for heading me in the right direction. – Peter Mar 12 '14 at 06:35
  • 1
    Unfortunately, if your App gets in there, it won't get out. Try to change the app identifier. If you feel like I helped, then I'd appreciate an upvote on one of my answers. Unfortunately, this one is not possible to answer until we figure out collaboratively your real issue. – allprog Mar 12 '14 at 07:36

0 Answers0