Cannot find connected accessory if EAAccessoryManager.shared() is called in AppDelegate constructor

635 Views Asked by At

If I call EAAccessoryManager.shared() inside the AppDelegate constructor e.g.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var accessoryManager = EAAccessoryManager.shared()

  ...

  func application(
    _ application: UIApplication,  
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    return true
  }
  ...
}

Then later I access the accessory manager to get connected accessories (with an accessory connected) EAAccessoryManager.shared().connectedAccessories.count returns 0, which is incorrect.

If I don't call EAAccessoryManager.shared() in the AppDelegate constructor, then EAAccessoryManager.shared().connectedAccessories.count returns 1, which is correct.

I can workaround this problem, but I really wanted to understand why this might be happening, as I could have misunderstood something about how the EAAccessoryManager is meant to work (or perhaps something more fundamental about how an app is initialised - I am new to iOS programming).

Has anyone hit this problem before, or maybe have an idea why this could be happening?

0

There are 0 best solutions below