"isConnected" deprecated in iOS 7

I know this is a stupid question, but here.

I have an older application that uses isConnected. Now I get a warning that it is out of date. Can I just delete this line of code without any branching or how to do it. Sorry for being so tight.

here is some code from CBPeripheral framework.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
    // Deal with errors (if any)
    if (error) {
        NSLog(@"Error discovering characteristics: %@", [error localizedDescription]);
        [self cleanup];
        return;
    }
}
- (void)cleanup
{
    // Don't do anything if we're not connected
    if (!self.discoveredPeripheral.isConnected) // here is where the warning comes {
        return;
    }

I think I found the answer should be

- (void)cleanup
    {
        // Don't do anything if we're not connected
        if (CBPeripheralStateDisconnected)  {
            return;
        }

I also added @property (read-only) state to CBPeripheralState; in my .h

I'm not wrong. Can anyone confirm this for me?

+4
source share
1 answer

As Apple Documentation says:

Isconnected

, , . ( ) ( iOS 7.0. .)

:

if (self.discoveredPeripheral.state != CBPeripheralStateConnected)
    return;

, , , . , . , - ... ?

+14

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


All Articles