 
     private func accessoryConnected(notification: NSNotification) {
         log("Accessory Connected Notification")
-        // Ignore accessory connection state notifications when application is not active.
-        if UIApplication.sharedApplication().applicationState != .Active {
+        if applicationInactive {
+            // Ignore accessory connection state notifications when application is not active.
             return
         }
 


    private func accessoryDisconnected(notification: NSNotification) {
        log("Accessory Disconnected Notification")
        // Ignore accessory connection state notifications when application is not active.
        if UIApplication.sharedApplication().applicationState != .Active {
            return
        }


    private var observers: [ObserverProxy] = []
    private let smartcardQueue: dispatch_queue_t
    private var retryingConnection: Bool = false
    private var applicationInactive: Bool = false

    // Communication objects
    private let smartcard = PBSmartcard()
