Question

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. In order to interact with devices, you need to have a class that handles communication with EAAccessory objects. To do this, you have to define your device connectivity class with the EAAccessoryDelegate protocol.

The EAAccessoryDelegate protocol contains one method--

– accessoryDidDisconnect:(EAAccessory *)accessory.

The Apple documentation states:

The EAAccessoryDelegate protocol defines a single method for receiving notifications when the associated EAAccessory object is disconnected. Implementation of this method is optional.

When you are instantiating your class, you can register your own methods with the NSNotificationCenter system. 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.

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.

With that said, what is the point of the – accessoryDidDisconnect: method when it's never really used? 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.

I know this is a knit-picky question but I am quite curious.

Was it helpful?

Solution

This is a pretty common design pattern with Apple, to provide a short-cut for very common NSNotificationCenter notifications. On OS X, they do this with a lot of the NSWindow notifications, passing along the contents of NSNotification in those cases.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top