     }
     
     
-    func appDidBecomeActive() {
-        println("Discovery Manager: did become active")
+    func appWillEnterForeground() {
+        println("Discovery Manager: will enter foreground")
         
         if self.centralManager?.state == CBCentralManagerState.PoweredOn {
             self.startScanning()

    func centralManager(central: CBCentralManager!, didDisconnectPeripheral peripheral: CBPeripheral!, error: NSError!) {
        println("Called did Disconnect Peripheral: \(peripheral)")
        
        nc.postNotificationName("btStateChangedNotification", object: "Disconnected", userInfo: ["peripheral": peripheral])
        
        // when activePeripheral is set to nil we know we don't need to reconnect.
        if (peripheral == self.activePeripheral) {
            self.resetConnection()
            self.startScanning()
        }
    }
    

    override init() {
        super.init()
        
        nc.addObserver(
            self,
            selector: Selector("appDidEnterBackground"),
            name: UIApplicationDidEnterBackgroundNotification,
            object: nil)
        
        nc.addObserver(
            self,
            selector: Selector("appWillEnterForeground"),
            name: UIApplicationWillEnterForegroundNotification,
            object: nil
        )
        
        let queue = dispatch_queue_create("no.malt", DISPATCH_QUEUE_SERIAL)
        centralManager = CBCentralManager(delegate: self, queue: queue)
        
        rssiTimer = NSTimer.scheduledTimerWithTimeInterval(
            2.0,
            target: self,
            selector: Selector("doReadRSSI"),
            userInfo: nil,
            repeats: true
        )
    }
    
    func sayHello() -> String {
