CBperipheral uuid is null in ios 6.0.1 on i-phone5
Asked Answered
T

3

9

well, I have an application that scan and connect to to a 'bluetooth le' device under ios 6.0.1 but on iphone 4s, and it works good. when upload the application to the apple store, they return me an application crash, bat programming, but I only understand the crash when I try the application on an iphone5 where the

 - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI; 

return me a peripheral with null uuid.

I print the peripheral, the name, the uuid, the rssi and the advertData, everything is good but the uuid is null, and I use the uuid in the application. this make my application crash, I can control the null uuid, and this means that I can't control the application.

Somebody knows what happens, and a possible solution?

Tristan answered 4/12, 2012 at 23:41 Comment(3)
porssible solution is next.Tristan
I found the soluttion, asking the uuid after services were read. Only when the connection was stablished you can know and the consult the uuid of the device... see you soonTristan
I have code that uses this call back, when run on iPad, I get a non bil periferial.UUI, but it is null on iPhone 6.0.1Darby
T
2

What we have to do is the next: You cant write the peripheral object with a NSLog, but we can't have the peripheral uuid property before connect was executed. It always was null. We ask for the uuid when the services read was finished, not before, and then we can't run the applications on i-phone5 without crash.

I read it about on TI (texas instruments) that it was a ios bug, but I thing it is a ble security update, we need to connect before ask fore the uuid.

Tristan answered 10/12, 2012 at 11:17 Comment(0)
S
1

After the first connection, the UUID is remembered/cached by the device. If the same peripheral is discovered at a later time, the UUID will be available before connection. You can ask for all remembered peripherals by calling "retrievePeripherals".

Stylo answered 19/12, 2012 at 22:36 Comment(0)
S
0

It appears to be a bug/feature enhancement in iOS 6, that makes itself more apparent on the iPhone 5 I think due to the asynchronous nature of the code. I too have code that works on the 4S but not on the 5.

The workaround posted by most people is to make sure you connect to every device you find as you find it. The explanation being that the UUID is not assigned until a connection is made.

You can see an example of this in the TI sensor tag code which you can download from the TI site

-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {

    NSLog(@"Found a BLE Device : %@",peripheral);

    /* iOS 6.0 bug workaround : connect to device before displaying UUID !
       The reason for this is that the CFUUID .UUID property of CBPeripheral
       here is null the first time an unkown (never connected before in any app)
       peripheral is connected. So therefore we connect to all peripherals we find.
    */

    peripheral.delegate = self;
    [central connectPeripheral:peripheral options:nil];

    [self.nDevices addObject:peripheral];

}

However it is noticeable that you can also do the following

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSLog(@"didDiscoverPeripheral");

    if (![foundPeripherals containsObject:peripheral]) {
        NSLog(@"foundPeripherals addObject %@", peripheral.name);
        [foundPeripherals addObject:peripheral];
    } else {
        NSInteger index = [foundPeripherals indexOfObject:peripheral];
        NSLog(@"foundPeripherals replaceObject %@", peripheral.name);
        [foundPeripherals replaceObjectAtIndex:index withObject:peripheral];
    }

}

as didDiscoverPeripheral gets called more than once for each device (I see it called twice on the iPhone 5) and the second time the peripherals details are complete.

Seismo answered 3/6, 2013 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.