Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Core Bluetooth not discovering peripherals

I'm having trouble getting Core Bluetooth to discover peripherals on iOS 8. Same code works fine on iOS 7 device. Initially I thought it would be a permissions issue since I had been doing some iBeacon work and there are some changes in Core Location permissions on iOS 8. I couldn't find anything online that helped with that however. Here is a link to a sample project that works fine for me on iOS 7 but not on iOS 8:

https://github.com/elgreco84/PeripheralScanning

If I run this project on an iOS 7 device it will log advertisement data for a number of devices around me. On iOS 8 the only output I see is that the Central Manager state is "Powered On".

like image 212
Rick Roberts Avatar asked Aug 30 '14 20:08

Rick Roberts


People also ask

Does iOS support classic Bluetooth?

iOS supports and connects to two different type of Bluetooth devices – one that is termed as BLE – Bluetooth Low Energy device and the other is a Bluetooth classic device.

What is core Bluetooth in iOS?

The Core Bluetooth framework provides the classes needed for your apps to communicate with Bluetooth-equipped low energy (LE) and Basic Rate / Enhanced Data Rate (BR/EDR) wireless technology.

How do I enable ble on my Iphone?

On your iOS device go into "Settings-> Bluetooth" and turn on your BLE device. You should see the device listed in your available devices.

What is Cbuuid?

A universally unique identifier, as defined by Bluetooth standards.


1 Answers

It isn't valid to start scanning for peripherals until you are in the 'powered on' state. Perhaps on your iOS7 device you are lucky with timing, but the code is still incorrect. Your centralManagerDidUpdateState: should be

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    switch (central.state)
    {
        case CBCentralManagerStateUnsupported:
        {
            NSLog(@"State: Unsupported");
        } break;

        case CBCentralManagerStateUnauthorized:
        {
            NSLog(@"State: Unauthorized");
        } break;

        case CBCentralManagerStatePoweredOff:
        {
            NSLog(@"State: Powered Off");
        } break;

        case CBCentralManagerStatePoweredOn:
        {
            NSLog(@"State: Powered On");
            [self.manager scanForPeripheralsWithServices:nil options:nil];
        } break;

        case CBCentralManagerStateUnknown:
        {
            NSLog(@"State: Unknown");
        } break;

        default:
        {
        }

    }
}

And remove the call to scanForPeripheralsWithServices from didFinishLaunchingWithOptions

like image 170
Paulw11 Avatar answered Nov 04 '22 16:11

Paulw11