 
     override func viewWillDisappear(animated: Bool) {
         super.viewWillDisappear(animated)
-        self.updatePeripheralConnectionsSwitch = true
         self.stopPollingRSSIForPeripherals()
     }
 

    }

    func connect(peripheral: BCPeripheral) {
        let future = peripheral.connect(10, timeoutRetries: ConfigStore.getMaximumReconnections(), connectionTimeout: Double(ConfigStore.getPeripheralConnectionTimeout()))
        future.onSuccess { (peripheral, connectionEvent) in
            switch connectionEvent {
            case .Connect:
                BCLogger.debug("Connected")
                Notify.withMessage("Connected peripheral: '\(peripheral.name)'")
                self.updateWhenActive()
            case .Timeout:


    var peripheralsSortedByRSSI: [BCPeripheral] {
        return Singletons.centralManager.peripherals.sort() { (p1, p2) -> Bool in
            if p1.RSSI == 127 && p2.RSSI != 127 {
                return false
            }  else if p1.RSSI != 127 && p2.RSSI == 127 {
                return true
            } else if p1.RSSI == 127 && p2.RSSI == 127 {
                return true
            } else {
                return p1.RSSI >= p2.RSSI
            }
        }
    }

