简体   繁体   English

EAAccessoryDe​​legate中的– annexDidDisconnect:方法的目的是什么?

[英]What is the purpose of the – accessoryDidDisconnect: method within the EAAccessoryDelegate?

I've been working on an iOS implementation that is connecting to hardware and, as such, I am having to make use of the External Accessory framework. 我一直在研究与硬件连接的iOS实现,因此,我不得不使用外部附件框架。 In order to interact with devices, you need to have a class that handles communication with EAAccessory objects. 为了与设备进行交互,您需要具有一个与EAAccessory对象进行通信的类。 To do this, you have to define your device connectivity class with the EAAccessoryDelegate protocol. 为此,您必须使用EAAccessoryDelegate协议定义设备连接类。

The EAAccessoryDelegate protocol contains one method-- EAAccessoryDelegate协议包含一种方法-

– accessoryDidDisconnect:(EAAccessory *)accessory . – accessoryDidDisconnect:(EAAccessory *)accessory

The Apple documentation states: Apple文档指出:

The EAAccessoryDelegate protocol defines a single method for receiving notifications when the associated EAAccessory object is disconnected. EAAccessoryDelegate协议定义了一种方法,当关联的EAAccessory对象断开连接时,该方法用于接收通知。 Implementation of this method is optional. 此方法的实现是可选的。

When you are instantiating your class, you can register your own methods with the NSNotificationCenter system. 实例化类时,可以在NSNotificationCenter系统中注册自己的方法。 When there is either a Device Connect or Device Disconnect event you can handle the event as you desire. 当发生设备连接或设备断开事件时,您可以根据需要处理该事件。 When the Device Disconnect event occurs, the purpose of the - accessoryDidDisconnect: is rendered pointless because it provides the exact same functionality and data to your class. 发生“设备断开连接”事件时, - accessoryDidDisconnect:目的变得毫无意义,因为它为您的类提供了完全相同的功能和数据。

Furthermore, ever example that I can find regarding working with the External Accessory Framework gives examples of detecting device connectivity changes via the NSNotificationCenter subscription mechanism. 此外,我能找到的有关使用外部附件框架的所有示例都提供了通过NSNotificationCenter订阅机制检测设备连接更改的示例。

With that said, what is the point of the – accessoryDidDisconnect: method when it's never really used? 话虽如此,当从未真正使用过– accessoryDidDisconnect:方法的意义是什么? Yes, it can be implemented but as I mentioned, all forms of documentation recommend that you manage these types of connectivity changes through the NSNotificationCenter . 是的,可以实现,但是正如我提到的,所有形式的文档都建议您通过NSNotificationCenter管理这些类型的连接更改。

I know this is a knit-picky question but I am quite curious. 我知道这是一个挑剔的问题,但我很好奇。

This is a pretty common design pattern with Apple, to provide a short-cut for very common NSNotificationCenter notifications. 这是Apple很常见的设计模式,为非常常见的NSNotificationCenter通知提供了捷径。 On OS X, they do this with a lot of the NSWindow notifications, passing along the contents of NSNotification in those cases. 在OS X上,它们使用大量NSWindow通知来执行此操作,在这种情况下,它们会传递NSNotification的内容。

Basically, it's an easy way to implement the notification without having to make sure that you add and remove your observer. 基本上,这是一种实现通知的简单方法,而无需确保添加和删除观察者。

In particular, this is used only after an EAAccessory object has been created (which only happens after the accessory is connected) and thus, having the connect method wouldn't be applicable at this time. 特别是,此方法仅在创建EAAccessory对象之后才使用(仅在连接附件后才发生),因此,具有connect方法目前不适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM