Detect metawear disconnect from iOS SDK

I need to know when metawear get disconnected in order to call the connect handler. 

This way when the device move out of range and come back it can be connected automatically. 


Thanks

Comments

  • edited April 2015
    The MBLMetaWear object has a "state" property which contains the connection state.  This property is KVO compliant  so you add an observer to be notified of state changes.

    After connected start observing like this:

    [self.device addObserver:self forKeyPath:@state options:NSKeyValueObservingOptionNew context:nil];


    Make sure to implement the KVO callback method:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

    {

        if (self.device.state == CBPeripheralStateDisconnected) {

            // Note there is an automatic retry feature internal to the MetaWear

    // framework, so this gets called after an unsuccessful connect too. That's

    // why you should only observe a connected device, we are in the process

    // of cleaning this up. 

        }








    }


This discussion has been closed.