What should my app do to access the device name property?

Asked on 2024-07-30

1 search

To access the device name property of an accessory in your app, you can use the asaccessory object from the AccessorySetupKit. When an accessory is ready to use, your app will receive an accessoryadded event. By reading the accessory property from this event, you get an asaccessory object that represents the newly set up accessory. This object includes properties such as the display name, which can be changed in settings.

Here is a relevant segment from the session "Meet AccessorySetupKit":

When an accessory is ready to use, the app would get an accessoryadded event. By reading the accessory property from this event, we get an asaccessory object that represents our newly setup dice. Some other events include accessory changed, which is sent when properties of the accessory have changed, such as display name, which can be changed in settings. Accessory removed is sent when the accessory was removed from the system, either by the user or your app. The as accessory class represents a physical accessory. It has the accessory's authorization state, display name Discovery descriptor, and all of its networking interfaces, including a Bluetooth identifier of the CB peripheral and a Wi Fi ssid if it broadcasts a Wi Fi network with the as accessory object. From the accessory added event, we we can use core Bluetooth to connect to the Bluetooth peripheral. We'll create a CB central manager as always, since we declared accessory setup kit support in our info plist, unlike previous versions of iOS, people will not be asked for permission to use Bluetooth. The CB central manager state will only become powered on when your app has paired accessories. In our case, we have our pink dice.

For more details, you can refer to the session Meet AccessorySetupKit (09:40).