如果我在 AppDelegate 构造函数中调用 EAAccessoryManager.shared() 例如
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var accessoryManager = EAAccessoryManager.shared()
...
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
...
}
然后稍后我访问附件管理器以获取连接的附件(连接了附件)EAAccessoryManager.shared().connectedAccessories.count返回 0,这是不正确的。
如果我不在 AppDelegate 构造函数中调用 EAAccessoryManager.shared() ,则EAAccessoryManager.shared().connectedAccessories.count返回 1,这是正确的。
我可以解决这个问题,但我真的很想了解为什么会发生这种情况,因为我可能误解了 EAAccessoryManager 的工作原理(或者可能是关于如何初始化应用程序的更基本的东西 - 我是 iOS 新手编程)。
以前有没有人遇到过这个问题,或者可能知道为什么会发生这种情况?