     func appWillEnterForeground() {
         println("Discovery Manager: will enter foreground")
         
-        if self.centralManager?.state == CBCentralManagerState.PoweredOn {
-            self.startScanning()
-        }
-        else {
-            println("  App became active but Bluetooth not on.")
+        if let central = self.centralManager {
+            if central.state == CBCentralManagerState.PoweredOn {
+                self.startScanning()
+            }
+            else {
+                println("  App became active but Bluetooth not on.")
+            }
         }
     }
     

            object: nil
        )
        
        let queue = dispatch_queue_create("no.malt", DISPATCH_QUEUE_SERIAL)
        centralManager = CBCentralManager(delegate: self, queue: queue)
        
        rssiTimer = NSTimer.scheduledTimerWithTimeInterval(
            2.0,

        
        var msg = "Low Signal: \(signal)"
        nc.postNotificationName("btStateChangedNotification", object: msg)
        if let central = self.centralManager {
            central.stopScan()
            self.resetConnection()
        }
        
        delay(1.0) {
            // Wait one second to start scanning again.
