In my application I am using HomeKit. You can add/remove HMHome and HMRoom object, but I would also like to add some metadata to them. For example in my application I want to be able to add an icon to a HMRoom and add an Array of items to it too.
My solution is that I use it in combination with CoreData and store the extra information about the HMRoom, but there is no way to identify the HMHome and HMRoom objects, other than their name. This would not be a problem if my application would be the only application in the world to edit the HomeKit objects, but of course there could be other applications, also adjusting the HMHome and HMRoom objects (removing them, renaming them).
So I would really have a problem, when the user does one of the following things:
Because there is no known identifier for the HMHome and HMRoom objects, I cannot find the metadata I stored in CoreData anymore and that metadata is actually lost, because I can no longer match the name with the created HMRoom with the data in my CoreData database.
So, my question is: Is there a way to 'identify' HMRoom and HMHome objects other than their name?
In iOS9, you can use the uniqueIdentifier to always identify the same object. This UUID stays the same whether the room gets renamed.
According to the documentation there is no other identifier for HMHome
and HMRoom
than the name. But they both have accessories
property, and HMAccessory
has the identifier property, which is persistent (at least until the user removes an accessory and adds it again, which wouldn't be a common thing to see, I hope).
So you can save accessories assigned to a given home or room along with other metadata. And if the home's or room's name changes, in most of the cases you should still be able to detect what the original name was, looking at the stored accessories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With