Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如果在AppDelegate构造函数中调用了EAAccessoryManager.shared(),则找不到连接的附件_Ios_Swift_External Accessory_Eaaccessory - Fatal编程技术网

Ios 如果在AppDelegate构造函数中调用了EAAccessoryManager.shared(),则找不到连接的附件

Ios 如果在AppDelegate构造函数中调用了EAAccessoryManager.shared(),则找不到连接的附件,ios,swift,external-accessory,eaaccessory,Ios,Swift,External Accessory,Eaaccessory,如果我在AppDelegate构造函数内调用EAAccessoryManager.shared(),例如 @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var accessoryManager = EAAccessoryManager.shared() ... func application( _ application: UIApplication,

如果我在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编程不熟悉)


以前有没有人遇到过这个问题,或者可能知道为什么会发生这种情况?

我不知道原因(可能过早调用会导致问题),但是存储对
EAAccessoryManager.shared()的引用有什么意义
在属性中?在实际代码中,我使用EAAccessoryManager.shared()创建了一个更复杂的对象,但我简化了代码以隔离问题。有解决方案吗?我也有同样的问题。