HomeKit HMHome and HMRoom IDs / Additional Metadata

In my application, I am using HomeKit. You can add / remove HMHome and HMRoom objects, but I would also like to add some metadata to them. For example, in my application I want to add an icon in HMRoom and also add an array of elements to it.

My solution is that I use it in conjunction with CoreData and keep additional information about HMRoom, but there is no way to identify HMHome and HMRoom objects other than their name. This will not be a problem if my application is the only application in the world for editing HomeKit objects, but, of course, there may be other applications, as well as setting up HMHome and HMRoom objects (deleting them, renaming them).

So, I really have a problem when the user does one of the following:

  • Run my application
  • Add HMHome and HMRoom
  • Add some metadata to the HMRoom object through my application, which is stored in my CoreData database li>
  • Complete my application
  • Launch another application and rename only created HMRoom.
  • Launch my app again

Since there is no unknown identifier for the HMHome and HMRoom objects, I can no longer find the metadata stored in CoreData, and that the metadata is actually lost, because I can no longer match the name with the created HMRoom to the data in my CoreData Database.

So my question is: is there a way to identify HMRoom and HMHome objects other than their name?

+5
source share
2 answers

In iOS9, you can use uniqueIdentifier to always identify the same object. This UUID remains the same whether the premises will be renamed.

+3
source

According to the documentation for HMHome and HMRoom there is no identifier other than a name. But both of them have the accessories property, and the HMAccessory has the identifier property, which is permanent (at least until the user removes it and adds it again, which, in my opinion, will not be distributed.)

Thus, you can save the accessories assigned to a given house or room along with other metadata. And if the name of the house or room changes, in most cases you can still determine what the original name is by looking at the saved accessories.

+1
source

Source: https://habr.com/ru/post/1213375/


All Articles